-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6_(bool,operator,list).py
361 lines (314 loc) · 6.24 KB
/
6_(bool,operator,list).py
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
Python 3.12.3 (tags/v3.12.3:f6650f9, Apr 9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
a=10
b=5
if (a>b):
print("a is g")
else:
SyntaxError: invalid syntax
if (a>b):
print("a is g")
else:
SyntaxError: invalid syntax
if (a>b):
print("a is g")
else:
print("b is g")
a is g
print(bool("hello"))
True
print(bool(15))
True
print("abc")
abc
bool("abc")
True
bool(123)
True
bool(abc)
Traceback (most recent call last):
File "<pyshell#15>", line 1, in <module>
bool(abc)
NameError: name 'abc' is not defined. Did you mean: 'abs'? Or did you forget to import 'abc'?
print(bool(False))
False
print(bool())
False
class myclass():
def__len__(self):
SyntaxError: invalid syntax
class myclass():
def__len__(self):
SyntaxError: invalid syntax
class myclass():
def __len__(self):
return 0
myob= myclass()
SyntaxError: invalid syntax
class myclass():
def __len__(self):
return 0
myob= myclass()
SyntaxError: invalid syntax
class myclass():
def __len__(self):
return 0
myob = myclass()
print(bool(myob))
Traceback (most recent call last):
File "<pyshell#28>", line 1, in <module>
class myclass():
File "<pyshell#28>", line 5, in myclass
myob = myclass()
NameError: name 'myclass' is not defined
class myclass():
def __len__(self):
return 0
myob= myclass()
print(bool(myob))
False
def myfun():
return true
print(myfun())
Traceback (most recent call last):
File "<pyshell#36>", line 1, in <module>
print(myfun())
File "<pyshell#35>", line 2, in myfun
return true
NameError: name 'true' is not defined. Did you mean: 'True'?
def myfun():
return true
print(myfun())
Traceback (most recent call last):
File "<pyshell#39>", line 1, in <module>
print(myfun())
File "<pyshell#38>", line 2, in myfun
return true
NameError: name 'true' is not defined. Did you mean: 'True'?
def myfun():
return true
print(myfun())
SyntaxError: invalid syntax
def myfun():
return true
print(myfun())
SyntaxError: unindent does not match any outer indentation level
def myfun():
return true
print(myfun())
SyntaxError: unindent does not match any outer indentation level
def myfun():
return True
print(myfun())
True
def myFun():
return True
if myFun():
print("Yes!")
else:
print("No")
Yes!
x= 200
print(isinstance(x,int))
True
print(5%3)
2
print(2**5)
32
print(2*2*2*2*2)
32
print(15 //2)
7
x =5
x -=3
print(x)
2
print( 5%=3)
SyntaxError: invalid syntax
print(5 %=3)
SyntaxError: invalid syntax
print(5 %= 3)
SyntaxError: invalid syntax
x =5
x %=3
print(x)
2
x=5
x **=3
print(x)
125
x=5
x >>= 3
print(x)
0
print(x := 3)
3
x = 5
y =3
print(x == y)
False
print(x !=3)
True
print(x>=y)
True
x = 5
print( x> 3 and x<10)
True
print(x>3 or x<10)
True
print(not(x>3 and x<10))
False
x=["apple","bannana"]
y=["apple","bannana"]
z=x
print(x is z)
True
print(x is y)
False
print(x == y)
True
print("banana" in x)
False
print("kiwi" in x)
False
print9 6 & 3)
SyntaxError: unmatched ')'
print(6 & 3)
2
print(6 | 3)
7
print(6 ^ 3)
5
print(~3)
-4
print(3<<6)
192
print(3>>6)
0
print((6+3) -(6+3))
0
print(100 + 5*3)
115
print(8 >>4-2)
2
print(5 ==4+1)
True
print9 not 4==4)
SyntaxError: unmatched ')'
print(not 4==4)
False
print(5+4-7+3)
5
thislist =["apple","banana","cherry"]
print(thislist)
['apple', 'banana', 'cherry']
print(len(thislist))
3
list1=[1,2,3,5,8]
list2=[True,False,False]
print(list1,list2)
[1, 2, 3, 5, 8] [True, False, False]
print(type(list1))
<class 'list'>
print(thislist[1])
banana
print(thislist[-1])
cherry
this[1:3] =["bt","watermelon"]
Traceback (most recent call last):
File "<pyshell#130>", line 1, in <module>
this[1:3] =["bt","watermelon"]
NameError: name 'this' is not defined. Did you forget to import 'this'?
thislist[1:3] =["bt","watermelon"]
print(thislist)
['apple', 'bt', 'watermelon']
thislist.append("orange")
print(thislist)
['apple', 'bt', 'watermelon', 'orange']
thislist.extend(list1)
print(thislist)
['apple', 'bt', 'watermelon', 'orange', 1, 2, 3, 5, 8]
thislist.remove("orange")print(thislist)
SyntaxError: invalid syntax
thislist.remove("orange")
print(thislist)
['apple', 'bt', 'watermelon', 1, 2, 3, 5, 8]
thislist.clear()
print(thislist)
[]
for x in list1:
print(x)
1
2
3
5
8
thislist = ["apple", "banana", "cherry"]
for i in range(len(thislist)):
print(thislist[i])
apple
banana
cherry
i=0
while i< len(thislist):
print(thislist[i])
i++
SyntaxError: invalid syntax
while i< len(thislist):
print(thislist[i])
i= i+1
apple
banana
cherry
fruits = ["apple", "banana", "cherry", "kiwi", "mango"]
KeyboardInterrupt
fruits = ["apple", "banana", "cherry", "kiwi", "mango"]
newlist =[]
for x in fruits:
if "a" in x:
newlist.append(x)
print(newkist)
Traceback (most recent call last):
File "<pyshell#163>", line 1, in <module>
print(newkist)
NameError: name 'newkist' is not defined. Did you mean: 'newlist'?
>>> print(newlist)
['apple', 'banana', 'mango']
>>>
>>> fruits =["apple","banna","cherry","kiwi"]
>>> newlist =[x for x in fruits if "a" in x]
>>> print(newlist)
['apple', 'banna']
>>>
>>> fruits= ["apple","banna","ch"]
>>> newlist= [x for x in fruits if "a" in x]
>>> print(newlist)
['apple', 'banna']
>>> fruits =["apple","banna","cherry","kiwi"]
>>> thislist.sort()
>>> print(thislist)
['apple', 'banana', 'cherry']
>>> this=[100,50,65,82,23]
>>> this.sort(reverse=True)
>>> print(thislist)
['apple', 'banana', 'cherry']
>>> mylist= thislist.copy()
>>> print(mylist)
['apple', 'banana', 'cherry']
>>> ['apple', 'banana', 'cherry']
['apple', 'banana', 'cherry']
>>>
>>> list1 = ["a", "b" , "c"]
>>> list2 = [1, 2, 3]
>>>
>>> for x in list2:
... list1.append(x)
...
...
>>> print(list1)
['a', 'b', 'c', 1, 2, 3]
>>>
>>> fruits = ['apple', 'banana', 'cherry']
>>> fruits.reverse()
>>> print(fruits)
['cherry', 'banana', 'apple']