-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy path3_variables.py
62 lines (43 loc) · 1.36 KB
/
3_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# a variable is a place to store data that can change
# python is a dynamically-typed language a.k.a weakly-typed
# java is a strongly-typed language a.k.a statically-typed
# python variable - we just give it a name
first_name = 'Victoria'
print(first_name)
print(type(first_name))
last_name = "Lloyd"
print(last_name)
print(type(last_name))
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
# This is NOT Python - this is JAVA
# String firstName = "Victoria";
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
# concatenation (gluing strings together)
print(first_name)
print(last_name)
full_name = first_name + last_name
print(full_name)
full_name_with_space = first_name + ' ' + last_name
print(full_name_with_space)
chips = 2.50
fish = 4.50
total_cost = fish + chips
print(total_cost)
# operator overloading
# '+' is either concatenation when given strings to work with
# or '+' is addition when given numbers to work with
dinner = 2.50
dinner = dinner + fish
dinner = dinner + 'mushy_peas'
print('The price of dinner is ' + str(dinner))
# short-hand syntax (augmented assignment) / compound operators
dinner += fish
print('The price of dinner is ' + str(dinner))
dinner = dinner - chips
dinner -= chips
print('Friday')
print(123)
print(True)
print('hello', 'Zippy', 'George')
print('hello', 7, 'George', 11)
print('hello ' + str(7))