-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythonreview.py
More file actions
198 lines (138 loc) · 2.31 KB
/
pythonreview.py
File metadata and controls
198 lines (138 loc) · 2.31 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#APS106 Midterm 1 review
#1 - ARHITMETIC OPERATORS AND PRECEDNECE
#addition
print(2 + 2)
#4
#subtraction
print(-2 - -1.3)
#-0.7
#multiplication
print(2*4)
#8
#power
print(2**3)
#8
#division
print(4/-2.3)
#-1.7391304347826089
#floor division - rounds to closest whole number
print(4//-2.3)
#-2,
#actually -1.7391304347826089, but rounds UP to closest whole #
print(4//2.3)
#1
#4/2.3 is 1.7391304347826089, but rounds DOWN to closest whole #
#modulus (think of this like remainder)
print(8%3)
#2
print(9%3)
#0
'''
Precedence (highest to loweest)
**
- (negation not subtraction)
*, /, //, % (evaluate left to right)
+, - (left to right)
'''
x = 2 + 5*2 **2
# 2 + 5*(4)
# 2 + 20
print(x)
#22
#2 - BUILTINS
#takes the absolute value
x = abs(-2)
print(x)
#2
x = True
print(bool(x))
print(chr(65))
#A
print(ord("A"))
#65
print(chr(97))
#a
print(ord("a"))
#97
print(float(23))
str1 = "geek"
print(id(str1))
#returns identity of an object
print(len("hello"))
#5
print(len("ciao"))
#4
key = 2.0
x = isinstance(key, float)
print(x)
print(round(23.238, 2))
#3 - ESCAPE SEQUENCES
#\n = NEW LINE
print("Hi my \n name is Vanessa")
#\' = SINGLE QUOTES
print("Hi my name is \'Vanessa\'")
#\" = DOUBLE QUOTES
print("Hi my name is \"Vanessa\"")
#\\ - when u wanna print \n
print("Hi my name is \\n Vanessa")
import math
print(math.ceil(-1.2))
#-1
print(math.ceil(1.2))
#2
print(math.floor(1.2))
#1
print(math.floor(-1.2))
#FLOOR AND CEIL WOR COUNTERINTUITIVELY FOR HOW U THINK THEY WOULD FOR NEG VALUES
#-2
#(math.degrees) = converts an angle from radians to degrees
print(math.e)
#2.718281828459045
print(math.sqrt(2))
#1.4142135623730951
print(not True)
#False
print(not not True)
#True
#4 - RATIONAL COMPARASIN
print(2 != 3)
#True
print(True == False)
#False
print(2==3)
#False
num = 4
num += 1
print(num)
x = 4
x -= 1
print(x)
y = 4
y *= 2
print(y)
#5 -STRINGS
#concatication
print("Hello" + "z")
#Helloz
print("2" + "3")
#23
print("Ciao" * 4)
#CiaoCiaoCiaoCiao
a = "Hello, World!"
print(a[1])
#e
z = "I'm boutta go off on this midterm"
print(z[-1])
#m
b = "Hello, World!"
print(b[2:5])
#INCLUSIVE ON FIRST, EXCLUSIVE ON LAST
swag = "ur nan"
print(swag[3:6])
a = "Hello, World!"
print(a.replace("H", "J"))
a = "Hello, World!"
print(a.split(",")) # returns ['Hello', ' World!']
a = "baguette"
print(a.rfind("e"))
#7