-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path02_variables.py
42 lines (34 loc) · 1.22 KB
/
02_variables.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# When you write code like below you create a variable.
x = 123
# We have created a variable called "x" and assigned it the value
# 123. python will on our behalf reserve some memory and store the
# value 123 in it.
# Whenever we would like to access this value we need to use the
# variable name "x".
print(x)
# Important!
# Notice that print("x") means something different than print(x)
# The former tells python to display the text "x", where as the
# latter tells python to display the value of variable x.
# We can create as many variables as we need.
my_age = 42
birth_year = 1980
a = 999
# Variable names can not contain spaces.
# Variable's name should hint what it will be used for.
pi = 3.14
current_season = "November"
welcome_message = "Welcome to our homepage"
# this is a bad name
three = 3
# this is much better
max_cards_per_user = 3
# variables can be used in many ways
current_year = birth_year + my_age
print(current_year)
print(welcome_message + " in " + current_season)
# exercise 1: create two variables, assign some big numbers to them
# and print their sum, difference, product (multiplication),
# quotient (division)
# exercise 2: create two variables, assign some text to them and
# display the concatenated text.