SlideShare a Scribd company logo
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

Functions in Python
Functions in PythonFunctions in Python
Functions in Python
Kamal Acharya
 
Class, object and inheritance in python
Class, object and inheritance in pythonClass, object and inheritance in python
Class, object and inheritance in python
Santosh Verma
 
Sorting in python
Sorting in python Sorting in python
Sorting in python
Simplilearn
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in python
Celine George
 
Variables & Data Types In Python | Edureka
Variables & Data Types In Python | EdurekaVariables & Data Types In Python | Edureka
Variables & Data Types In Python | Edureka
Edureka!
 
Chapter 0 Python Overview (Python Programming Lecture)
Chapter 0 Python Overview (Python Programming Lecture)Chapter 0 Python Overview (Python Programming Lecture)
Chapter 0 Python Overview (Python Programming Lecture)
IoT Code Lab
 
PART 4 - Python Tutorial | If Else In Python With Examples
PART 4 - Python Tutorial | If Else In Python With ExamplesPART 4 - Python Tutorial | If Else In Python With Examples
PART 4 - Python Tutorial | If Else In Python With Examples
Shivam Mitra
 
Python functions
Python functionsPython functions
Python functions
Prof. Dr. K. Adisesha
 
Python - Lecture 11
Python - Lecture 11Python - Lecture 11
Python - Lecture 11
Ravi Kiran Khareedi
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
Yi-Fan Chu
 
Sub-programs
Sub-programsSub-programs
Sub-programs
Forrester High School
 
Namespaces
NamespacesNamespaces
Namespaces
Sangeetha S
 
Python array
Python arrayPython array
Python array
Arnab Chakraborty
 
Basic data types in python
Basic data types in pythonBasic data types in python
Basic data types in python
sunilchute1
 
Tuples in Python
Tuples in PythonTuples in Python
Tuples in Python
DPS Ranipur Haridwar UK
 
What is Dictionary In Python? Python Dictionary Tutorial | Edureka
What is Dictionary In Python? Python Dictionary Tutorial | EdurekaWhat is Dictionary In Python? Python Dictionary Tutorial | Edureka
What is Dictionary In Python? Python Dictionary Tutorial | Edureka
Edureka!
 
Python list
Python listPython list
Reading and Writing Files
Reading and Writing FilesReading and Writing Files
Reading and Writing Files
primeteacher32
 
Python Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | EdurekaPython Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | Edureka
Edureka!
 

What's hot (20)

Functions in Python
Functions in PythonFunctions in Python
Functions in Python
 
Class, object and inheritance in python
Class, object and inheritance in pythonClass, object and inheritance in python
Class, object and inheritance in python
 
Sorting in python
Sorting in python Sorting in python
Sorting in python
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in python
 
Variables & Data Types In Python | Edureka
Variables & Data Types In Python | EdurekaVariables & Data Types In Python | Edureka
Variables & Data Types In Python | Edureka
 
Chapter 0 Python Overview (Python Programming Lecture)
Chapter 0 Python Overview (Python Programming Lecture)Chapter 0 Python Overview (Python Programming Lecture)
Chapter 0 Python Overview (Python Programming Lecture)
 
SQL
SQLSQL
SQL
 
PART 4 - Python Tutorial | If Else In Python With Examples
PART 4 - Python Tutorial | If Else In Python With ExamplesPART 4 - Python Tutorial | If Else In Python With Examples
PART 4 - Python Tutorial | If Else In Python With Examples
 
Python functions
Python functionsPython functions
Python functions
 
Python - Lecture 11
Python - Lecture 11Python - Lecture 11
Python - Lecture 11
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Sub-programs
Sub-programsSub-programs
Sub-programs
 
Namespaces
NamespacesNamespaces
Namespaces
 
Python array
Python arrayPython array
Python array
 
Basic data types in python
Basic data types in pythonBasic data types in python
Basic data types in python
 
Tuples in Python
Tuples in PythonTuples in Python
Tuples in Python
 
What is Dictionary In Python? Python Dictionary Tutorial | Edureka
What is Dictionary In Python? Python Dictionary Tutorial | EdurekaWhat is Dictionary In Python? Python Dictionary Tutorial | Edureka
What is Dictionary In Python? Python Dictionary Tutorial | Edureka
 
Python list
Python listPython list
Python list
 
Reading and Writing Files
Reading and Writing FilesReading and Writing Files
Reading and Writing Files
 
Python Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | EdurekaPython Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | Edureka
 

Similar to Records in Python

python_class.pptx
python_class.pptxpython_class.pptx
python_class.pptx
chandankumar943868
 
python program
python programpython program
python program
tomlee12821
 
C
CC
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxINTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptx
Nimrahafzal1
 
Lesson 3.1 variables and constant
Lesson 3.1 variables and constantLesson 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.pptxCSV JSON and XML files in Python.pptx
CSV JSON and XML files in Python.pptx
Ramakrishna Reddy Bijjam
 
Python bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of NairobiPython bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of Nairobikrmboya
 

Similar to Records in Python (7)

python_class.pptx
python_class.pptxpython_class.pptx
python_class.pptx
 
python program
python programpython program
python program
 
C
CC
C
 
INTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptxINTRODUCTION TO PYTHON.pptx
INTRODUCTION TO PYTHON.pptx
 
Lesson 3.1 variables and constant
Lesson 3.1 variables and constantLesson 3.1 variables and constant
Lesson 3.1 variables and constant
 
CSV JSON and XML files in Python.pptx
CSV JSON and XML files in Python.pptxCSV JSON and XML files in Python.pptx
CSV JSON and XML files in Python.pptx
 
Python bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of NairobiPython bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of Nairobi
 

More from Forrester High School

Program Design
Program DesignProgram Design
Program Design
Forrester High School
 
Database Evaluation
Database EvaluationDatabase Evaluation
Database Evaluation
Forrester High School
 
Testing SQL
Testing SQLTesting SQL
SQL
SQLSQL
Database Query Design
Database Query DesignDatabase Query Design
Database Query Design
Forrester High School
 
Data Dictionary
Data DictionaryData Dictionary
Data Dictionary
Forrester High School
 
Compound Keys
Compound KeysCompound Keys
Compound Keys
Forrester High School
 
Entity Occurrence Diagrams
Entity Occurrence DiagramsEntity Occurrence Diagrams
Entity Occurrence Diagrams
Forrester High School
 
Entity Relationship Diagrams
Entity Relationship DiagramsEntity Relationship Diagrams
Entity Relationship Diagrams
Forrester High School
 
Database Analysis
Database AnalysisDatabase Analysis
Database Analysis
Forrester High School
 
Software Evaluation
Software EvaluationSoftware Evaluation
Software Evaluation
Forrester High School
 
Software Testing
Software TestingSoftware Testing
Software Testing
Forrester High School
 
Python Predefined Functions
Python Predefined FunctionsPython Predefined Functions
Python Predefined Functions
Forrester High School
 
Python Substrings
Python SubstringsPython Substrings
Python Substrings
Forrester High School
 
Variable Scope
Variable ScopeVariable Scope
Variable Scope
Forrester High School
 
SDD Predefined Functions
SDD Predefined FunctionsSDD Predefined Functions
SDD Predefined Functions
Forrester High School
 
SDD Cconditional Loops
SDD Cconditional LoopsSDD Cconditional Loops
SDD Cconditional Loops
Forrester High School
 
SDD Fixed Loops
SDD Fixed LoopsSDD Fixed Loops
SDD Fixed Loops
Forrester High School
 
SDD Conditional Statements
SDD Conditional StatementsSDD Conditional Statements
SDD Conditional Statements
Forrester High School
 
SD & D Arithmetic Operators
SD & D Arithmetic OperatorsSD & D Arithmetic Operators
SD & D Arithmetic Operators
Forrester High School
 

More from Forrester High School (20)

Program Design
Program DesignProgram Design
Program Design
 
Database Evaluation
Database EvaluationDatabase Evaluation
Database Evaluation
 
Testing SQL
Testing SQLTesting SQL
Testing SQL
 
SQL
SQLSQL
SQL
 
Database Query Design
Database Query DesignDatabase Query Design
Database Query Design
 
Data Dictionary
Data DictionaryData Dictionary
Data Dictionary
 
Compound Keys
Compound KeysCompound Keys
Compound Keys
 
Entity Occurrence Diagrams
Entity Occurrence DiagramsEntity Occurrence Diagrams
Entity Occurrence Diagrams
 
Entity Relationship Diagrams
Entity Relationship DiagramsEntity Relationship Diagrams
Entity Relationship Diagrams
 
Database Analysis
Database AnalysisDatabase Analysis
Database Analysis
 
Software Evaluation
Software EvaluationSoftware Evaluation
Software Evaluation
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Python Predefined Functions
Python Predefined FunctionsPython Predefined Functions
Python Predefined Functions
 
Python Substrings
Python SubstringsPython Substrings
Python Substrings
 
Variable Scope
Variable ScopeVariable Scope
Variable Scope
 
SDD Predefined Functions
SDD Predefined FunctionsSDD Predefined Functions
SDD Predefined Functions
 
SDD Cconditional Loops
SDD Cconditional LoopsSDD Cconditional Loops
SDD Cconditional Loops
 
SDD Fixed Loops
SDD Fixed LoopsSDD Fixed Loops
SDD Fixed Loops
 
SDD Conditional Statements
SDD Conditional StatementsSDD Conditional Statements
SDD Conditional Statements
 
SD & D Arithmetic Operators
SD & D Arithmetic OperatorsSD & D Arithmetic Operators
SD & D Arithmetic Operators
 

Recently uploaded

Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 

Recently uploaded (20)

Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 

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}