-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython
More file actions
executable file
·121 lines (100 loc) · 2.92 KB
/
python
File metadata and controls
executable file
·121 lines (100 loc) · 2.92 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
history
compiled & interpreted
process of compilation:
tokenisation
syntax analysis
sementic analysis
intermidate code generation - does code optization
python follows reference model.
c follows value model.
Datatypes:
Number:
integer -
decimal -
complex -
-> arithmatic operator:
** power
// floor division
+
-
*
/
%
-> relational operator:
>
<
>=
<=
==
<> - not equal to in 2.7
!= - not equal to in 3.4
-> logical operator:
or - a or b
and - a and b
-> identity operator:- Compare two object's ID.
is
is not
-> membership operation:
in
not in
Example:
>>> a = 5
>>> b = 5
>>> a is b
True
>>> id(a) is id(b)
False
>>> id(a) == id(b)
True
>>> id(a) == id(b)
is - compare value
== compare id
-> bitwise operator
& - bitwise and operator - turn on
| - bitwise or operator - turn off
^ - bitwise - toggle
~ - compliment - exactly opposite
>> - right shift: Perform division by 2x power
Arithmatic right shift
1 will get added
Logical right shift
0 will get added
<< - left shift: Perform multiplication by 2x power
funcations in python:
reusability
modular
standard methods:
type
input - scanf for anything other than string
raw_input - scanf for only string
eval(raw_input) - same as int
bit operations:
number = number & (number -1) -> this removes the right most 1 bit
default argument:
def new_fun(input_string, x, y = 100):
||
This is a default agrument
if we pass only 2 input to function then the function will use y = 10
if we pass 3 params to function then the function will use the value that is passed to function
keyword argument:
def new_fun(input, x, y)
we can call this function using:
new_fun(x = 100, y = 200, input="string")
HOMEWORK:- 4th Oct 2014
- WAP which will find all such numbers which are divisible by 7 and are not multiple of 5 between 1000 to 2500
- WAP to find a factorial of a given number
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
String slicing:
- s = "hello"
- s[x:y:z] :- x is start-index/inclusive & y is end-index/exclusive & z is step value(default step value is 1 and if -1 is given then the list will be sorted)
- start-index should always be less than end-index if both positive or negative.
- start-index should come before end index
-
HW:
WAP to implement stack using list - LIFO
isFull
isEmpty
push
pop
peep - view top
WAP to implement queue using list - FIFO