SlideShare a Scribd company logo
4
Most read
5
Most read
10
Most read
RECORDS IN PYTHON
Higher Computing Science
RUNNER RECORD
• A record is a special data structure which allows the programmer to
combine multiple data objects
• For example, a record might contain a string, an integer and a Boolean
• Think again about the runner example
• Instead of storing the name, bib number and elite status in three parallel
arrays, these could be stored in a single record
RUNNER RECORD
• The pseudocode for the runner record is shown below:
RECORD runner:
name: string
bib_number: integer
elite: Boolean
END RECORD
RUNNER RECORD
• To implement this code in Python we use a dictionary
runner = {
'name': 'John McGrain',
'bib_number': 1014,
'elite': False
}
RUNNER RECORD
• In Python, name, bib_number and elite are known as the dictionary keys
runner = {
'name': 'John McGrain',
'bib_number': 1014,
'elite': False
}
RUNNER RECORD
• We access dictionary keys like this:
print(runner[‘name’]) -> John McGrain
print(runner[‘bib_number’]) -> 1014
RUNNER RECORD
• We update the dictionary like this:
runner[‘name’] = ‘Billy Jones’
print(runner)
-> {'name': ‘Billy Jones’, 'bib_number': 1014,'elite':
False}
ARRAY OF RECORDS
• What if we want to store data about multiple runners?
• Then we create an array
• Instead of an array of integers, or an array of strings as we have seen
previously, we create and array of records
ARRAY OF RECORDS
• It would look like this:
runners =
[{'name': 'Ann', 'bib_number': 101, 'elite': False},
{'name': 'Jen', 'bib_number': 307, 'elite': True},
{'name': 'Tom', 'bib_number': 231, 'elite': False}]
• Notice we have 3 records each separated by a comma
• And these are all held within an array (we can tell by the square
brackets)
ARRAY OF RECORDS
• An array of records works in exactly the same way as any other array
print(runners[0])
-> {'name': 'Ann', 'bib_number': 101, 'elite': False}
print(runners[2])
-> {'name': 'Tom', 'bib_number': 231, 'elite': False}

More Related Content

What's hot (20)

List and Dictionary in python
List and Dictionary in python
Sangita Panchal
 
Python Programming
Python Programming
Saravanan T.M
 
Types of software
Types of software
uttraj888826
 
Introduction to python
Introduction to python
ManishJha237
 
Software Testing
Software Testing
Forrester High School
 
Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0
Salim M
 
Functions in Python
Functions in Python
Kamal Acharya
 
hardware and software upgrade
hardware and software upgrade
Dana Popescu
 
Python Keywords
Python Keywords
khanmusfera32
 
1.python interpreter and interactive mode
1.python interpreter and interactive mode
ManjuA8
 
Android chapter02-setup2-emulator
Android chapter02-setup2-emulator
guru472
 
Print input-presentation
Print input-presentation
Martin McBride
 
Programming Fundamentals Functions in C and types
Programming Fundamentals Functions in C and types
imtiazalijoono
 
How to execute a C program
How to execute a C program
Leela Koneru
 
Python Interpreter.pdf
Python Interpreter.pdf
SudhanshiBakre1
 
Introduction to c programming
Introduction to c programming
ABHISHEK fulwadhwa
 
Python Integrated Development Environment
Python Integrated Development Environment
TikendraPandey
 
Python basics
Python basics
RANAALIMAJEEDRAJPUT
 
Visual Basic Controls ppt
Visual Basic Controls ppt
Ranjuma Shubhangi
 
LPEs in KATANA and Maya
LPEs in KATANA and Maya
kedar nath
 
List and Dictionary in python
List and Dictionary in python
Sangita Panchal
 
Introduction to python
Introduction to python
ManishJha237
 
Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0
Salim M
 
hardware and software upgrade
hardware and software upgrade
Dana Popescu
 
1.python interpreter and interactive mode
1.python interpreter and interactive mode
ManjuA8
 
Android chapter02-setup2-emulator
Android chapter02-setup2-emulator
guru472
 
Print input-presentation
Print input-presentation
Martin McBride
 
Programming Fundamentals Functions in C and types
Programming Fundamentals Functions in C and types
imtiazalijoono
 
How to execute a C program
How to execute a C program
Leela Koneru
 
Python Integrated Development Environment
Python Integrated Development Environment
TikendraPandey
 
LPEs in KATANA and Maya
LPEs in KATANA and Maya
kedar nath
 

Similar to Records in Python (10)

python_class.pptx
python_class.pptx
chandankumar943868
 
python program
python program
tomlee12821
 
4. Tools Proyek Data Science DTS-TA v.3.pptx
4. Tools Proyek Data Science DTS-TA v.3.pptx
irvaimuhammad
 
C
C
Jerin John
 
avrointroduction-150325003254-conversion-gate01.pptx
avrointroduction-150325003254-conversion-gate01.pptx
kuthubussaman1
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptx
Nimrahafzal1
 
Lesson 3.1 variables and constant
Lesson 3.1 variables and constant
MLG College of Learning, Inc
 
CSV JSON and XML files in Python.pptx
CSV JSON and XML files in Python.pptx
Ramakrishna Reddy Bijjam
 
Instruction Formats in computer architecture.pptx
Instruction Formats in computer architecture.pptx
tgoswami1907
 
Python bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of Nairobi
krmboya
 
4. Tools Proyek Data Science DTS-TA v.3.pptx
4. Tools Proyek Data Science DTS-TA v.3.pptx
irvaimuhammad
 
avrointroduction-150325003254-conversion-gate01.pptx
avrointroduction-150325003254-conversion-gate01.pptx
kuthubussaman1
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptx
Nimrahafzal1
 
Instruction Formats in computer architecture.pptx
Instruction Formats in computer architecture.pptx
tgoswami1907
 
Python bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of Nairobi
krmboya
 
Ad

More from Forrester High School (20)

Program Design
Program Design
Forrester High School
 
Database Evaluation
Database Evaluation
Forrester High School
 
Testing SQL
Testing SQL
Forrester High School
 
SQL
SQL
Forrester High School
 
Database Query Design
Database Query Design
Forrester High School
 
Data Dictionary
Data Dictionary
Forrester High School
 
Compound Keys
Compound Keys
Forrester High School
 
Entity Occurrence Diagrams
Entity Occurrence Diagrams
Forrester High School
 
Entity Relationship Diagrams
Entity Relationship Diagrams
Forrester High School
 
Database Analysis
Database Analysis
Forrester High School
 
Software Evaluation
Software Evaluation
Forrester High School
 
Python Predefined Functions
Python Predefined Functions
Forrester High School
 
Python Substrings
Python Substrings
Forrester High School
 
Variable Scope
Variable Scope
Forrester High School
 
SDD Predefined Functions
SDD Predefined Functions
Forrester High School
 
SDD Cconditional Loops
SDD Cconditional Loops
Forrester High School
 
SDD Fixed Loops
SDD Fixed Loops
Forrester High School
 
SDD Conditional Statements
SDD Conditional Statements
Forrester High School
 
SD & D Arithmetic Operators
SD & D Arithmetic Operators
Forrester High School
 
N5 security precautions
N5 security precautions
Forrester High School
 
Ad

Recently uploaded (20)

IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
Vikas Bansal Himachal Pradesh: A Visionary Transforming Himachal’s Educationa...
Vikas Bansal Himachal Pradesh: A Visionary Transforming Himachal’s Educationa...
Himalayan Group of Professional Institutions (HGPI)
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
BINARY files CSV files JSON files with example.pptx
BINARY files CSV files JSON files with example.pptx
Ramakrishna Reddy Bijjam
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Nice Dream.pdf /
Nice Dream.pdf /
ErinUsher3
 
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
Publishing Your Memoir with Brooke Warner
Publishing Your Memoir with Brooke Warner
Brooke Warner
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
Sourav Kr Podder
 
Introduction to Generative AI and Copilot.pdf
Introduction to Generative AI and Copilot.pdf
TechSoup
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
LDMMIA Spring Ending Guest Grad Student News
LDMMIA Spring Ending Guest Grad Student News
LDM & Mia eStudios
 
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Pragya - UEM Kolkata Quiz Club
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
BINARY files CSV files JSON files with example.pptx
BINARY files CSV files JSON files with example.pptx
Ramakrishna Reddy Bijjam
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
Nice Dream.pdf /
Nice Dream.pdf /
ErinUsher3
 
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
Publishing Your Memoir with Brooke Warner
Publishing Your Memoir with Brooke Warner
Brooke Warner
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
Sourav Kr Podder
 
Introduction to Generative AI and Copilot.pdf
Introduction to Generative AI and Copilot.pdf
TechSoup
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
LDMMIA Spring Ending Guest Grad Student News
LDMMIA Spring Ending Guest Grad Student News
LDM & Mia eStudios
 
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Pragya - UEM Kolkata Quiz Club
 

Records in Python

  • 1. RECORDS IN PYTHON Higher Computing Science
  • 2. RUNNER RECORD • A record is a special data structure which allows the programmer to combine multiple data objects • For example, a record might contain a string, an integer and a Boolean • Think again about the runner example • Instead of storing the name, bib number and elite status in three parallel arrays, these could be stored in a single record
  • 3. RUNNER RECORD • The pseudocode for the runner record is shown below: RECORD runner: name: string bib_number: integer elite: Boolean END RECORD
  • 4. RUNNER RECORD • To implement this code in Python we use a dictionary runner = { 'name': 'John McGrain', 'bib_number': 1014, 'elite': False }
  • 5. RUNNER RECORD • In Python, name, bib_number and elite are known as the dictionary keys runner = { 'name': 'John McGrain', 'bib_number': 1014, 'elite': False }
  • 6. RUNNER RECORD • We access dictionary keys like this: print(runner[‘name’]) -> John McGrain print(runner[‘bib_number’]) -> 1014
  • 7. RUNNER RECORD • We update the dictionary like this: runner[‘name’] = ‘Billy Jones’ print(runner) -> {'name': ‘Billy Jones’, 'bib_number': 1014,'elite': False}
  • 8. ARRAY OF RECORDS • What if we want to store data about multiple runners? • Then we create an array • Instead of an array of integers, or an array of strings as we have seen previously, we create and array of records
  • 9. ARRAY OF RECORDS • It would look like this: runners = [{'name': 'Ann', 'bib_number': 101, 'elite': False}, {'name': 'Jen', 'bib_number': 307, 'elite': True}, {'name': 'Tom', 'bib_number': 231, 'elite': False}] • Notice we have 3 records each separated by a comma • And these are all held within an array (we can tell by the square brackets)
  • 10. ARRAY OF RECORDS • An array of records works in exactly the same way as any other array print(runners[0]) -> {'name': 'Ann', 'bib_number': 101, 'elite': False} print(runners[2]) -> {'name': 'Tom', 'bib_number': 231, 'elite': False}