-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbasics.py
More file actions
95 lines (68 loc) · 1.55 KB
/
basics.py
File metadata and controls
95 lines (68 loc) · 1.55 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Lesson 3 - Numbers
# https://www.youtube.com/watch?v=Gqby4v5JOu4&list=PL4cUxeGkcC9idu6GZ8EU_5B6WpKTdYZbK&index=3
# everything in Python is an object, and objects have attributes & methods that are functions
type(500)
# <class 'int'>
type(5.1)
# <class 'float'>
5 / 5
# 1.0 <= retruns a float
5 / 5
# 1 <= retruns an integer
10 % 3
# 1 <= remainder, or 'modulus'
5 ** 5
# 3125 <= 5 to the power of 5
5 + 5 * 3
# 20
(5 + 5) * 3
# 30
# (BIDMAS) Brackets -> Indices -> Multiplication -> Addition -> Subtraction
age = 25
age += 5 # or -= for the opposite
age
# 35
wages = 1000
bills = 200
rent = 500
food = 200
savings = wages - bills - rent - food
savings
# 100
# Lesson 4 - Strings
# https://www.youtube.com/watch?v=Gqby4v5JOu4&list=PL4cUxeGkcC9idu6GZ8EU_5B6WpKTdYZbK&index=4
noun = 'you\'re here' # canceler
greet = 'hello'
greet[0:4]
# 'hell'
greet[2:-1]
# 'll'
greet + " " + noun
# hello you're here
greet * 3
# 'hellohellohello'
greet.upper()
# Hello
len(greet)
# 5
cheeses = "Brie, Chedder, Stilton"
cheeses.split(',')
# ['Brie', 'Chedder', 'Stilton']
# Lesson 5 - Lists
# https://www.youtube.com/watch?v=Gqby4v5JOu4&list=PL4cUxeGkcC9idu6GZ8EU_5B6WpKTdYZbK&index=5
list1 = ['Bob', 'Tom', 'Ron'] # Ruby or JavaScript "array"
list1[1]
# 'Tom'
list2 = list1 + ["Cat"]
# ['Bob', 'Tom', 'Ron', 'Cat']
list2.append('Dan')
# ['Bob', 'Tom', 'Ron', 'Cat', 'Dan']
list2.pop() # removes the last item ('Dan')
# ['Bob', 'Tom', 'Ron', 'Cat']
list2.remove('Tom')
# ['Bob', 'Ron', 'Cat']
del(list2[0])
# ['Ron', 'Cat']
nest = [[1, 2], [3, 4], [5, 6]]
nest[2][1]
# 6