How to Use Len and in:
1 # _ * _ coding: UTF-8 _*_
2 # function Len returns the length of the list, that is, the number of elements
3 AA = [1, 2, 3, 4, 5]
4 print 'length of AA is ', Len (AA) # result: length of AA is 5
5 # You can use this value to traverse the list variables, which means that even if the list Length changes, we do not need
6 # modify the number of Rings
7 # example:
8 I = 0
9 while I <Len (AA ):
10 print AA [I]
11 I + = 1
12 # In is a boolean operator that tests whether the left operand is included in the list.
13 if 1 in AA:
14 print 'very good'
15 else:
16 print 'not bad'
17
18 # In can also test whether the string contains a certain character.
19 BB = '000000'
20 if '1' in BB:
21 print 'very good'
22 else:
23 print 'not bad'
For usage:
1 # _ * _ coding: UTF-8 _*_
2 test1 = ['monday', 'tuesday', 'wednesday', 'thursday', 'Friday', 'saturday', 'sunday']
3 # Use the For loop to traverse the list without repeating variables, which is more concise
4 for I in test1:
5 print I
6 # more examples
7 #1. Print all odd numbers between 0 and 19
8 test2 = range (20)
9 for I in test2:
10 if (I % 2 ):
11 print I
12