-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsefull Operators.py
More file actions
146 lines (68 loc) · 1.52 KB
/
Usefull Operators.py
File metadata and controls
146 lines (68 loc) · 1.52 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
#!/usr/bin/env python
# coding: utf-8
# In[1]:
list1 = [1,2,3,4]
# In[2]:
# range
# range is usfeul when we give range to loop using start , final and step size aswell range(start,stop,stepsize)
for num in range(10):
print(num)
# In[11]:
# loop form 1 to 5
for num in range(0,5):
print(num)
# In[14]:
# with step size 2
for num in range(0,10,2):
print(num)
# In[16]:
# making list
m_list=list(range(1,10,2))
m_list
# In[23]:
# suppose we have condition like this
# we need to print value and index both
my_str = 'uzair'
counter = 0
for item in my_str :
print(item)
print(counter)
counter+=1
# in this scenarior we are incrementing counter and iterate to the character of string so best practice is using wrd
#enumerate
# In[20]:
#enumerate
# In[24]:
for item in enumerate(my_str):
print(item)
# In[25]:
for index,item in enumerate(my_str):
print(item)
print(index)
# In[28]:
# zip
# zip is opposite to enumerate function
# let
myitem = [0,1,2,3,4]
myitem1 = ['u','z','a','i','r']
for item in zip(myitem,myitem1):
print(item)
# In[30]:
for item,val in zip(myitem,myitem1):
print(val)
print(item)
# In[31]:
list(zip(myitem,myitem1))
# In[32]:
# in keyword
# in usefull in loop aswell as in conditional aswell
"uzair" in ["uzair","iqbal"]
# In[33]:
# input
# input is use when want to get input from the user
result = input('input number')
result
# In[34]:
# other useful operators are
# min , max , randint
# In[ ]: