-
Overview of basic number types (7 Kind of )
- 10203 123 3340 int +- * / wait
- ' Did you eat today ?' str Store a small amount of data ,+ *int section , Other methods of operation
- True False bool Judge true or false
- [12, True, 'a1', [1,2,3 ]] list Store a lot of data .
- (12, True, 'a1', [1,2,3 ]) tuple Store a lot of data , You can't change the elements inside .
- {'name': ' Zhang San '} dict Store a lot of correlated data , Very fast query speed .
- set intersection , Union difference set ...
-
int
-
Decimal binary conversion
-
''' Binary to decimal 0001 1010 ------> ? 26 ''' b = 1 * 2**4 + 1 * 2**3 + 0 * 2**2 + 1 * 2**1 + 0 * 2**0 # print(b) # 26 ''' 42 -----> 0010 1010 '''
-
bit_lenth The effective length of decimal to binary
# bit_lenth Effective binary length i = 4 print(i.bit_length()) # 3 i = 5 print(i.bit_length()) # 3 i = 42 print(i.bit_length()) # 4
-
-
bool
-
bool str int The transition between the three
# bool str int # bool <---> int ''' True 1 False 0 Non zero means True 0 yes False ''' # str <---> int *** ''' s1 = 10 int(s1) : It has to be digital i = 100 str(i) ''' # str bool *** # It's not empty True s1 = ' ' print(bool(s1)) # True Spaces are also characters s1 = '' # An empty string print(bool(s1)) # False # bool ---> str meaningless print(str(True))
-
application :
s = input(' Input content ') if s: print(' There are content ') else: print(' No input ')
-
-
str
-
Index slice step size
s1 = 'python The whole stack 22 period ' # Index strings , The sliced data is of string type . # Value by index # There is an order from left to right , Subscript , Indexes . s2 = s1[0] print(s2,type(s2)) s3 = s1[2] print(s3) s4 = s1[-1] print(s4) # Value according to slice . # I don't care s5 = s1[0:6] s5 = s1[:6] print(s5) s6 = s1[6:] print(s6) # Slice step size s7 = s1[:5:2] print(s7) print(s1[:]) # In reverse order : s8 = s1[-1:-6:-1] print(s8) # By index :s1[index] # According to the slice : s1[start_index: end_index+1] # According to the slice step size : s1[start_index: end_index+1:2] # Reverse according to slice step size : s1[start_index: end_index One bit later :2] # Thinking questions : All in reverse order ?
-
Exercises
2. There are strings s = "123a4b5c" Through to s Slice to form a new string s1,s1 = "123" Through to s Slice to form a new string s2,s2 = "a4b" Through to s Slice to form a new string s3,s3 = "1345" Through to s Slice into strings s4,s4 = "2ab" Through to s Slice into strings s5,s5 = "c" Through to s Slice into strings s6,s6 = "ba2"
-
Common operation methods
# upper lower # s1 = s.upper() # # s1 = s.lower() # print(s1,type(s1)) # application : username = input(' user name ') password = input(' password ') code = 'QweA' print(code) your_code = input(' Please enter the verification code : Case insensitive ') if your_code.upper() == code.upper(): if username == ' The white ' and password == '123': print(' Login successful ') else: print(' Wrong username and password ') else: print(' Verification code error ')
-