-
Notifications
You must be signed in to change notification settings - Fork 6
/
Python.txt
240 lines (170 loc) · 3.77 KB
/
Python.txt
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
Module 1
50 Assignments
45 hours
162 non graded quiz
1 minor project
Assessment will be done in the end.
50 percent of the assessment will be done on module 4 project+presentation
50 percent is written examination (2x)
Word File to be maintained: (Assignment for each module)
Question+Solution+Snapshots
Submitted on blackboard.
Anaconda
Eclipse //
Pycharm
Oracle.
Python is a programmig as well as a scripting language.
Interpreted
Oops
Short and easy language
open source and free
comments==documentation
# signle line start and end
''' or """ triple single quotes start and end
use next line for continuation:: end line with backslash \
statements with () {} [] dont need \ for next line
python is case sensitive
print(" ",data type)
semicolon not needed
format specifiers not needed
print uses line concatenation
print("abc",10) answer= abc 10 (automatic space added)
inside print both single and double quotes can be used.
Two ways to print
print("%20s:%d"%('python',3000.34))
similar terminal as used in SQLPlus
Single variable has no data type. automatic assignment
Reference variable is object overhead.
type(variable)
write print(type(var)) for scripting.
string variable with mathematics
* concates same string without space n times
+ error
string + number is error
string+string is concatenation
scanning a value
input method
variable=input("message to user")
Every Input is a string by default
Typecase during or after the insertion
var=type(input())
or
after
var=type(var)
Tokens
1) Identifiers
same naming mechanism like C++ but see that Python keywords are different
no declaration
automatic assignment of data type
x=a+bj
a=real
b=imaginary
j=iota representation
print(x.real)
print(x.imag)
Different data types
integer
complex
float
string
boolean (True,False) //case sensitivity
2) Operators
2.1)Arithmetic
truncation division // gives integer quotation whereas mod % gives remainder
exponentiation **
3**2=9
2.2) Reltional
<> similar to not equal to !=
2.3) Assignment and Uniary Assignment operators also called shorthand assignment.
BCD assignment operator
a*=b+5 == a*=(b+5)
a=b=c=10 is allowed
a,b=2,5
swap values
a,b=b,a
2.4) Binary Operators
And
Or
Xor
Ones Complemetnt
left shift
right shift
2.5) logical
and
or
not
write like this it has no symbol all small
2.6) Membership operators simlilar to SQL
In
not in
2.7) Identity Operators
compare memory location
is
not is
memory location is given by id(var)
here value is not of variable because it changes with values
here values have address and the current variable is attached to it.
id("hello")
1)hence multiple variables having same value will point to same value hence memory is saved.
2)Comparison: If address is same values are same
Indentation
no blocks are required
indentations (tabs) are needed for the current block
example
if x>5: //condition can be without parenthesis
//if block
else:
//else block
elif cond: //else if is shortened
no switch case here
Looping
only entry
For and while
While
while condition:
statements
in looping every print automatically goes in next line
Increment operator is not used
Python Operators Precedence
The following table lists all operators from highest precedence to lowest.
[ Show Example ]
Sr.No. Operator & Description
1
**
Exponentiation (raise to the power)
2
~ + -
Complement, unary plus and minus (method names for the last two are +@ and -@)
3
* / % //
Multiply, divide, modulo and floor division
4
+ -
Addition and subtraction
5
>> <<
Right and left bitwise shift
6
&
Bitwise 'AND'
7
^ |
Bitwise exclusive `OR' and regular `OR'
8
<= < > >=
Comparison operators
9
<> == !=
Equality operators
10
= %= /= //= -= += *= **=
Assignment operators
11
is is not
Identity operators
12
in not in
Membership operators
13
not or and
Logical operators