In [1]:
locals()
Out[1]:
In [13]:
def f():
myvar = 'hello'
print locals()
f()
In [30]:
def my_dec(f):
def new_hello():
print "DECORATOR START"
f()
print "DECORATOR END"
return new_hello
@my_dec
def hello():
print 'Original hello!'
hello()
In [31]:
hello()
In [68]:
def simple_gen(start, stop):
for i in range(start, stop):
yield -i
In [70]:
g = simple_gen(5, 9)
In [75]:
next(g)
In [46]:
type(g)
Out[46]:
In [63]:
h = simple_gen()
In [67]:
next(h)
Out[67]:
In [76]:
import collections
In [83]:
x = ['a', 'b', 'c', 'b', 'b']
y = collections.Counter(x)
In [87]:
y.keys()
Out[87]:
In [91]:
y.most_common(1)
Out[91]:
In [101]:
x = collections.defaultdict(object)
In [99]:
x['dummy']
Out[99]:
In [103]:
import datetime
In [104]:
t = datetime.time(14, 59, 23)
In [105]:
t
Out[105]:
In [106]:
t + 2
In [109]:
t.isoformat()
Out[109]:
In [117]:
if None:
print "None"
else:
print "Something"
In [121]:
def f():
return None
if None:
print "None"
else:
print "Something"
In [122]:
partition("abcde", 'c')
In [123]:
'abcde'.partition('c')
Out[123]:
In [124]:
s = 'abcde'
In [125]:
s.partition('z')
Out[125]:
In [126]:
s.partition('d')
Out[126]:
In [127]:
s1 = {1,2,3}
s2 = {1,4,5}
In [128]:
s1.difference(s2)
Out[128]:
In [129]:
s1
Out[129]:
In [130]:
s2
Out[130]:
In [131]:
s1.difference_update(s2)
In [132]:
s1
Out[132]:
In [133]:
s2
Out[133]:
In [139]:
{k+'$$$':v**2 for k,v in zip(('a','b', 'c'), range(3,6))}
Out[139]:
In [140]:
[1,2] + [3,4]
Out[140]:
In [144]:
print [1,2].extend([3,4])
In [145]:
x = [1,2]
y = [3,4]
In [148]:
print x.extend(y)
In [147]:
print x
In [ ]: