This document is a lesson on Python data types, covering lists, dictionaries, tuples, and sets. It includes definitions, examples, and functions associated with each data type, as well as concepts like list comprehension and the use of for loops. The lesson aims to provide foundational knowledge for working with these data structures in Python.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
3 views
Lesson 4 Python.pptx
This document is a lesson on Python data types, covering lists, dictionaries, tuples, and sets. It includes definitions, examples, and functions associated with each data type, as well as concepts like list comprehension and the use of for loops. The lesson aims to provide foundational knowledge for working with these data structures in Python.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10
PYTHON
LESSON 4
CFGDEGREE → FOUNDATION MODULE
AGENDA
01 Python data types
02 Lists
03 Dictionaries LIST PYTHON DATA TYPE # EXAMPLES
● List: an ordered collection of lottery_numbers = [4, 8, 15, 16, 23, 42]
values student_names = ['Diedre', 'Hank', 'Helena', ● List are written inside square 'Salome'] brackets and separated by commas person = ['Jess', 32]
teams = [['Jenny', 'Mary'], ['Nigel', 'Steve']]
LIST FUNCTIONS DEFINITION # EXAMPLE
There are functions designed for lists costs = [1.2, 4.3, 2.0, 0.5]
● len(): the number of items in a list print(len(costs))
● max(): The biggest value in a list print(max(costs)) print(min(costs)) ● min(): The smallest value in a list
Functions for changing the order of a list
● sorted(): Sorts the
● reversed(): Reverses the order of a list LISTS & FOR LOOPS DEFINITION
DEMO & EXERCISES
to practice writing lists with For Loops
LIST COMPREHENSION DEFINITION # EXAMPLE
The syntax 'formula' for list comprehension is as follows:
● List comprehensions provide a concise way to create lists. new_list = [ expression for item in list if conditional ]
● It is a programmatically * 'if conditional' is optional
efficient way to create lists
● It is also a frequent question /
test for Python tests DICTIONARIES PYTHON DATA TYPE # EXAMPLE
● Dictionary: Stores a collection person = {
of labelled items. Each item 'name': 'Jessica', has a key and a value 'age': 23, 'height': 172 }
DEMO & EXERCISES
to practice writing Dictionaries
TUPLE PYTHON DATA TYPE # EXAMPLE
● Tuple: a Tuple is similar to List order = ('croissant', 'coffee', 'juice')
except that the objects in tuple are IMMUTABLE which means we CANNOT change the elements of a tuple once assigned.
● Tuple syntax uses ( ) brackets
● Tuple behaves very similar to
list SET PYTHON DATA TYPE # EXAMPLE
set: set is an unordered and unindexed
my_set = {1,2,3,4,5, 'hi', 7} collection of UNIQUE items in Python.
● Unordered means when we display
the elements of a set, it will come out in a random order. ● Unindexed means, we cannot access the elements of a set using the indexes like we can do in list and tuples. ● Set elements are unique. Duplicate elements are not allowed. ● Set uses {} THANK YOU!