In [ ]:
# how to print?
# but first thing, first. This is comment in my code using # (hash symbol) at the beginning of the line!
# don't forget to comment your code, it is important!
print('hello! my name is Anne.')
In [ ]:
# how to use variable?
# if I want to print multiple time something for example
my_name = 'Anne'
print('hi', my_name)
In [ ]:
?print
In [ ]:
print('hi', my_name, sep=',')
In [ ]:
# Everyone's happy? Questions?
In [ ]:
# four simple data types: integers, floats, booleans, and string of characters
In [ ]:
# strings
my_name = 'APajon' # is a string
print(my_name)
In [ ]:
# you can also check its type
type(my_name)
In [ ]:
# you can use different quotation ' " """
my_name = 'Anne'
my_family_name = "Pajon"
my_address = """11 Dream Street
Blue planet
"""
print(my_name, my_family_name)
print(my_address)
In [ ]:
some_text = 'my name's Anne'
In [ ]:
# concatenate strings together
print(my_name+my_family_name)
In [ ]:
print(my_name+10)
In [ ]:
print('23'+'5')
In [ ]:
# integers
i = 2
j = 5
i+j
In [ ]:
type(i)
In [ ]:
my_age = '23'
print(type(my_age))
my_age_in_10_years = int(my_age) + 10
print(my_age_in_10_years)
In [ ]:
# floats
x = 3.2
x*i
In [ ]:
x/5
In [ ]:
y = 2.4e3
print(y)
In [ ]:
type(y)
In [ ]:
i = 2
print(i)
i = float(i)
print(i)
In [ ]:
# booleans
print(True)
In [ ]:
print(False)
In [ ]:
type(True)
In [ ]:
?type
In [ ]:
?print
In [ ]:
print(i, j, y, sep=',')
In [ ]:
print(i, j, y, sep='\t')
In [ ]:
# undefined
empty = None
print(empty)
In [ ]:
# basic arithmetic
x = 3.2
y = 2
x+y
In [ ]:
x-y
In [ ]:
x*y
In [ ]:
x/y
In [ ]:
# be careful with division if you are using python 2!
2/3
In [ ]:
2.0/3
In [ ]:
float(2)/3
In [ ]:
# counting things
i = 1
print(i)
# do something first time
i = i + 1
print(i)
# do something else second time
i = i + 1
print(i)
# third time
In [ ]:
# there is a shortcut for this notation
i += 1
print(i)
In [ ]:
print(i)
i *= 2
print(i)
i -= 4
print(i)
In [ ]:
# do this exercise in a new notebook
# 1. download the python file and run it on the command line
# 2. python --version§§
# 3. add comment and change print statement
# 4. rerun
In [ ]:
cristian_age = 56
anne_age = 45
presenters_avg_age = (cristian_age + anne_age) / 2
print(presenters_avg_age)
Create a new Python file or Jupyter notebook to solve this exercise. It is good practice to create a new file each time you solve a new problem.