In [2]:
t = (1,2)
type(t)
Out[2]:
In [4]:
t = tuple()
type(t)
Out[4]:
In [5]:
t = tuple('test')
print t
In [6]:
l = list()
l.append(5)
l.append(6)
t = tuple(l)
print t
In [7]:
t = tuple( range(10) )
print t
In [8]:
print (5)
print (5,)
In [9]:
print (5+3)
print (5+3,)
In [10]:
print type( (5) )
print type( (5,) )
In [11]:
print [5]
print [5,]
In [12]:
print range(2)
In [13]:
a, b = range(2)
print a
print b
In [14]:
a,b,c = range(2)
In [15]:
d = {1:2,2:3,3:4}
print d.keys()
print d.values()
print d.items()
In [17]:
for key in d:
print key
In [18]:
for value in d.values():
print value
In [20]:
for items in d.items():
print items
In [22]:
for key, value in d.items():
print "key:", key
print "value:", value
In [23]:
div = 7 / 3
rem = 7 % 3
print "div:",div
print "rem:",rem
In [24]:
div, rem = divmod(7,3)
print "div:",div
print "rem:",rem
In [26]:
def addall(*nums):
total = 0
for n in nums:
total = total + n
return total
print addall(1,2,3,5)
In [30]:
t = (7,3)
print divmod(*t)
In [31]:
word = "frog"
nums = [1,2,3,4]
print zip(word,nums)
In [32]:
d = dict( zip(word,nums) )
print d
In [36]:
d.update( [ ('b',2), ('f', 4) ] )
print d
In [34]:
l = [1,2,3,4,5]
for i in range( len(l) ):
print i, l[i]
print ""
for i,val in enumerate(l):
print i,val
In [33]: