File tree 1 file changed +44
-0
lines changed
1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ cars = ['audi' , 'bmw' , "subaru" , 'toyota' ]
2
+
3
+ # if-elif-else--进入一个后不会再进另一个
4
+ for car in cars :
5
+ if car == 'bmw' :
6
+ print (car .upper ())
7
+ elif car == 'audi' :
8
+ print (car + ' is my car' )
9
+ else :
10
+ print (car .title ())
11
+
12
+ # python是区分大小写的
13
+ print (cars [- 1 ] == 'bmw' )
14
+ # lower()和upper()是不会改变原值的
15
+ print (cars [0 ].upper () == 'AUDI' )
16
+
17
+ # 判断不相等
18
+ print (cars [- 2 ].title () != 'subaru' )
19
+
20
+ # 多条件检查(与或)--and&or
21
+ print ((cars [0 ] == 'audi' ) and (cars [- 1 ] == 'toyota' ))
22
+ print ((cars [0 ] == 'audi' ) or (cars [- 1 ] == 'subaru' ))
23
+
24
+ # 检测特定值是否在列表中
25
+ print ('audi' in cars )
26
+ print ('bmw' not in cars )
27
+
28
+ # 确定列表是否为空
29
+ teachers = []
30
+ if teachers :
31
+ print ("Have teachers" )
32
+ else :
33
+ print ('Empty Array!' )
34
+
35
+ # 练习
36
+ names = ['admin' , 'lily' , 'lucy' , 'tom' ]
37
+ if names :
38
+ for name in names :
39
+ if name == 'admin' :
40
+ print ('Hello admin, would you like to see a status report?' )
41
+ else :
42
+ print ('hello ' + name + ',thank you logging in again' )
43
+ else :
44
+ print ('No names' )
You can’t perform that action at this time.
0 commit comments