In [1]:
odds = [1, 3, 5, 7]
print 'odds are:', odds
In [2]:
print 'first number:', odds[0], 'last number:', odds[-1]
In [3]:
for number in odds:
print number
In [4]:
for number in '1357':
print number
In [5]:
names = ['Newton', 'Darling', 'Plaatje']
print 'names are originally:', names
names[1] = 'Darwin'
print 'names are now:', names
In [6]:
string = 'Hello'
print 'string is now:', string
string[0] = 'h'
print 'string is now:', string
In [7]:
string = 'Hello'
print 'string is now:', string
string = 'hello'
print 'string is now:', string
In [9]:
odds = [1,3,5,7]
print 'odds are:', odds
odds.append(9)
print 'odds are:', odds
In [10]:
del odds[0]
print 'odds is now:', odds
odds.reverse()
print 'odds is now:', odds
In [12]:
odds = [1,3,5,7]
primes = odds
primes.append(2)
print primes
print odds
In [15]:
odds = [1,3,5,7]
#primes = odds[0:4]
primes = odds[:]
primes.append(2)
print primes
print odds
In [17]:
mystring = 'hello'
mylist = list(mystring)
print mylist
print type(mylist)
Typecasting
In [27]:
num = 53
num_str = str(num)
num = num + 5
num_str = num_str + '5'
print num, num_str
num_float = float(num)
print num_float
num_list = [num]
print num_list
In [26]:
float(5) / 2
Out[26]:
In [37]:
odds = [1,3,5,7,9,11]
# this gives you nothing
reversed_odds = odds.reverse()
print reversed_odds
odds = [1,3,5,7,9,11]
reversed_odds = odds[::-1]
print reversed_odds
print odds[1::2]
print range(1,12,2)
print range(11,0,-2)
In [47]:
odds = range(11,0,-2)
num = odds[0]
#odds.append(num)
#odds = odds + [num]
odds += [num]
del odds[0]
print odds
In [49]:
odds = range(11, 0, -2)
#num = odds.pop(0)
#odds.append(num)
odds.append(odds.pop(0))
print odds
In [ ]: