Introduction to Python
Hugo Bowne-Anderson
Data Scientist at DataCamp
Maximum of list: max()
Length of list or string: len()
Get index in list: ?
Reversing a list: ?
sister = "liz"
height = 1.73
fam = ["liz", 1.73, "emma", 1.68,
"mom", 1.71, "dad", 1.89]
sister = "liz"
height = 1.73
fam = ["liz", 1.73, "emma", 1.68,
"mom", 1.71, "dad", 1.89]
sister = "liz"
height = 1.73
fam = ["liz", 1.73, "emma", 1.68,
"mom", 1.71, "dad", 1.89]
fam
['liz', 1.73, 'emma', 1.68, 'mom', 1.71, 'dad', 1.89]
fam.index("mom") # "Call method index() on fam"
4
fam.count(1.73)
1
sister
'liz'
sister.capitalize()
'Liz'
sister.replace("z", "sa")
'lisa'
Everything = object
Object have methods associated, depending on type
sister.replace("z", "sa")
'lisa'
fam.replace("mom", "mommy")
AttributeError: 'list' object has no attribute 'replace'
sister.index("z")
2
fam.index("mom")
4
fam
['liz', 1.73, 'emma', 1.68, 'mom', 1.71, 'dad', 1.89]
fam.append("me")
fam
['liz', 1.73, 'emma', 1.68, 'mom', 1.71, 'dad', 1.89, 'me']
fam.append(1.79)
fam
['liz', 1.73, 'emma', 1.68, 'mom', 1.71, 'dad', 1.89, 'me', 1.79]
Functions
type(fam)
list
Methods: call functions on objects
fam.index("dad")
6
Introduction to Python