Class 5
strings II
loops in python II
strings - accessing
>>> s = 'Don Quijote'
>>> s[4] # Get the 5th character
'Q'
>>> s[2]
?
>> len(s)
?
string - slicing
>>> s = 'Don Quijote'
>>> s[4:8]
'Quij'
>>> s = 'Don Quijote'
>>> s[1:3]
?
>>> s[4:]
string - split()
>>> s = 'Don Quijote'
>>> [Link]()
[‘Don’, ‘Quijote’]
>>> ord(s[1]) #show the value ascii
Listas
>>> lista = [1, ‘a’, 45]
>>> lista
[1, ‘a’, 45]
>>> lista[1:]
?
>>> len(lista)
?
Listas
>>> lista = range(0, 10)
>>> lista
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Listas
Method Description
append(x) Appends object obj to list
count Returns count of how many times obj
occurs in list
sort() Sorts objects of list, use compare func if
given
for loop
for item in sequence:
#statements
problems