In [2]:
print "Hello world"
In [10]:
True
Out[10]:
In [11]:
False
Out[11]:
In [1]:
foo = True
In [2]:
foo
Out[2]:
In [2]:
2+2
Out[2]:
In [3]:
2*2
Out[3]:
In [4]:
"ala ma kota"
Out[4]:
In [5]:
"ala ma kota"[4:6]
Out[5]:
In [6]:
"ala ma kota"[4:]
Out[6]:
In [7]:
"ala ma kota"[:6]
Out[7]:
In [8]:
"ala ma kota"[::2]
Out[8]:
In [9]:
"ala ma kota"[::-1]
Out[9]:
In [32]:
"foo bar".split()
Out[32]:
In [33]:
"foo, bar".split(", ")
Out[33]:
In [36]:
"foo".upper()
Out[36]:
In [37]:
"FOO".lower()
Out[37]:
In [38]:
"foo".capitalize()
Out[38]:
In [12]:
a = [1, 5, 'foo', 7]
In [13]:
a
Out[13]:
In [15]:
a.append(4)
In [16]:
a
Out[16]:
In [17]:
a.extend([51, 67])
In [18]:
a
Out[18]:
In [44]:
foo = {'foo': 'bar', 'kopytko': 'no elo'}
In [45]:
foo
Out[45]:
In [46]:
foo['srogie'] = 'grzyby'
In [47]:
foo
Out[47]:
In [48]:
foo.update({'aaa': 'bbb', 'nieee': 'wspaniale'})
In [49]:
foo
Out[49]:
In [14]:
bool(1)
Out[14]:
In [15]:
bool(0)
Out[15]:
In [10]:
bool('foo')
Out[10]:
In [11]:
bool('')
Out[11]:
In [25]:
bool([2])
Out[25]:
In [20]:
bool([])
Out[20]:
In [21]:
bool({'foo': 'bar'})
Out[21]:
In [22]:
bool({})
Out[22]:
In [54]:
str(4)
Out[54]:
In [55]:
int('5')
Out[55]:
In [56]:
int('no witam')
In [12]:
if True:
print "To sie wyswietli"
else:
print "A to nie"
In [13]:
a = 5
if a == 2:
print "dwojka"
elif a == 5:
print "piatka"
else:
print "jakas liczba"
In [23]:
for i in xrange(10):
print i
In [24]:
for element in [5, 2, 8]:
print element
In [27]:
for key, value in {'foo': 'bar', 'kopytko': 'no elo'}.iteritems():
print key
print value
print
In [28]:
[i for i in xrange(10)]
Out[28]:
In [30]:
["%s -> %s" % (k, v) for k, v in {'foo': 'bar', 'kopytko': 'no elo'}.iteritems()]
Out[30]:
In [31]:
{i: i**2 for i in xrange(10)}
Out[31]:
In [34]:
def foo():
return 'bar'
In [35]:
print foo()
In [41]:
def foo(label):
return label.capitalize()
In [42]:
foo('foo')
Out[42]:
In [52]:
def foo(*args, **kwargs):
result = {element: element.capitalize() for element in args}
result.update(kwargs)
return result
In [53]:
foo('tak', 'nie', 'nie wiem', przypadek='nie sadze')
Out[53]:
In [57]:
def powers(limit):
for i in xrange(limit):
yield i**2
In [58]:
my_powers = powers(3)
In [59]:
next(my_powers)
Out[59]:
In [60]:
next(my_powers)
Out[60]:
In [61]:
next(my_powers)
Out[61]:
In [62]:
next(my_powers)
In [63]:
for i in powers(3):
print i
In [64]:
list(powers(3))
Out[64]: