In [3]:
print('Hello world!')
In [4]:
my_var = 1
my_var
Out[4]:
In [7]:
my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
In [10]:
my_list[0]
Out[10]:
In [11]:
my_string = "Hello world"
my_string[0]
Out[11]:
In [12]:
"HeLlO WoRlD".lower()
Out[12]:
In [15]:
" HeLlO WoRlD ".strip()
Out[15]:
In [16]:
"hello world".split(" ")
Out[16]:
In [17]:
'; '.join(['hello', 'world'])
Out[17]:
In [18]:
capital_cities = {'Poland': 'Warsaw', 'Belarus': 'Minsk', 'Czech': 'Prague'}
capital_cities['Poland']
Out[18]:
In [21]:
country = input("What country are you looking for?")
if country in capital_cities:
print('We know a caplital of {0}: "{1}"'.format(country, capital_cities[country]) )
else:
input_var = input("Please help me, what is the capital of " + country + ": ")
capital_cities[country] = input_var.strip()
In [23]:
capital_cities
Out[23]:
In [27]:
output_list = []
for x in range(10):
output_list.append(x) #append elemnt into list
output_list
Out[27]:
In [28]:
def doubled_fun(value):
return value * 2
output_list = []
for x in range(10):
output_list.append( doubled_fun(x) )
output_list
Out[28]:
In [29]:
my_list = range(10)
list(my_list)
Out[29]:
In [31]:
def doubled_fun(value):
return value * 2
list( map(doubled_fun, my_list) )
Out[31]:
In [32]:
list( map(lambda x: x*2, my_list) )
Out[32]:
In [33]:
[x for x in range(10)]
Out[33]:
In [34]:
[x*2 for x in range(10)]
Out[34]:
In [35]:
[x*2 for x in range(10) if x % 2 == 0]
Out[35]:
In [ ]: