I,Integer
1.
Relationship between digit size and bit
. Bit_length # How do I query the digits?
Conversion between boolean values (bool) and numbers
True False
N = bool (6)
Output True? # Can numbers and boolean values be converted to each other?
INT (true)
Output 1
#? CAN numbers and boolean values be converted to each other ?, During conversion, only zero is false, and the rest are true.
# When a Boolean value is converted to a number, true is 1false, and 0 is ??
# True if the string and boolean values are not empty during conversion
2.
String details
Method:
. Title # title in upper case ?? Only when special characters are separated can they be considered as multiple words. (Chinese is also a special character.
The first letter of. capitalize is capitalized, regardless of the number of words in the string. Only the first letter is capitalized.
. Upper () Make all letters in the word uppercase
. Lower? () Make all letters in the word lower case
. Count () count?
. Find () Search location ?, -1 is returned if the query does not exist.
If the. Index () index does not exist, an error is returned.
. Center? () Place the first digit in the center and the second digit in the content to be filled
. Split () # split? When there is no input in the brackets, the default space is to split the strings by cutting the characters in the brackets, and put the separated strings in a list for output. # String Conversion to list
. Strip () # Remove the spaces and linefeeds at both ends by default ??. What is the beginning and end of the deleted content?
Application scenarios:When a user logs in, it can eliminate the errors caused by spaces on the password account.
. Join () # specifies the concatenation of characters?
S = Name. replase ('x', 'n') # Replace the first one with the replaced content, and the second one with the replaced content ??
Name. startswith () # What does the computer start ?, The obtained result is a Boolean value.
Name. endswith () # ask at what end the obtained result is a Boolean Value
. Format () # format the content in the brackets into the variable {}:
? # It can be filled according to the placeholder position
? # It can also be filled by index.
# Fill according to the keyword?
Is series methods:?
. Isalnum? () # Determine whether it is a number or a letter
. Isalpha? () # Determine whether it is a pure letter
. Isdigit () # determine if it is a pure number
. Isupper () # determine whether it is a capital letter
. Islower (# Is it a lowercase letter?
# Remove spaces when a user logs on
:Press Ctrl + C to copy the code Press Ctrl + C to copy the code
# Application scenarios of the upper and. Lower methods:?
The verification code is used for a long time :? YZM = 'o98k ':
Y_zm = input ('input Verification Code o98k: ') If y_zm.upper () = YZM. Upper (): Print (' correct! '?? Else: Print ('error ')
Subscript (INDEX): M e t
0 1 2 3?
? -4-3-2-1
Slice; [start position: end position: Step Size] Ignore tail
Switch from left to right: []
Right-to-left: [-1:-4:-1]? The following 1 and-1 refer to the direction, where + refer to left-to-right and-refer to right-to-left. After the second colon, it refers to the step size.
# Interview questions:
Output the reverse response of 'I am moving like this, you are not responding below'
Name = 'I am moving like this, but you didn't respond to 'print (name [:-1]) below.
# Indicates the overall output if the start position is left blank.
# Interview questions:
How can I convert a string to a list through a line of code ??, At the same time, convert the list to a string using a line of code.
? Convert using method. Split (). Join ()
name = ‘alex‘print(name.split())?lst = [‘1‘,‘2‘,‘3‘]s =‘_‘.join(lst)??
??
For Loop (traversal loop)
For (keyword) + I (variable) + in (keyword) + iteratable object ??? (Except that numbers are all iteratable objects)
? A For Loop is a finite loop. The number of loops depends on the number of elements in the iteration object.
Classroom Essays
#-*-Coding: UTF-8-*-# convert numbers to boolean values ''' n = bool (1) print (n) N0 = bool (0) print (N0) n00 = bool (-1) print (n00) n1 = int (true) print (N1) N2 = int (false) print (N2) ''' # number of digits ''' n = 600 print (N. bit_length () ''' # Use '''name = 'Alex uwu Sir 'print (name. center (15, '*') # center, place the character in the middle, and add the preceding number to print (name. split ('U') # split the string by cutting the characters in the brackets, meanwhile, put the split string in a list and output S = '_'. join (name) # insert, insert _ in the middle of each character in the variable name print (Nam E. replase ('A', 'I') # Replace. The previous content is replaced, and the subsequent content is print (name. startswith () # ask what the variable starts with print (name. endswith () # ask the variable at what end print (name. count ('W') # Count print (name. title () # print (name. capitalize () # print (name. lower () # print (name. upper () # print (name. find ('M') # output-1 print (name. index ('l') # index, if it does not exist, the following error occurs: ''' # formatting ''' name = '{2}. {1} {0}'s = Name. format ('xx ', 'fucking', 'beautiful') # print (S) S1 = Name. format ('xx ', 'fucking', 'pretty ') print (S1) name1 = '{A} {B} {c} 's2 = name1.format (A = 'xx', B = 'fucking ', c = 'pretty ') print (S2) ''' # Remove space ''' name = 'Alex 'print (name. strip () user = input ('enter account :'). strip () Pwd = input ('Enter the password :'). strip () If user = 'Alex 'and Pwd = 'alex3714': Print ('entered correctly') else: Print ('entered incorrectly ') ''' # verification code example ''' YZM = 'os98k' Y _ ZM = input ('input Verification Code o98k: ') If y_zm.upper () = YZM. upper (): Print ('correct! ') Else: Print ('error') ''' # how to convert a string to a list using a line of code ??, At the same time, convert the list into a string using a line of code: '''name = 'Alex wumsp' print (name. split ('s') lst = ['1', '2', '3'] S = '_'. join (name) print (s) ''' # determine whether it is a pure number. The output data type is '''num = input ('enter a number: ') If num. isdigit (): num = int (Num) print (type (Num) else: Print ('all tell you the number ') ''' # subscript index''' name = 'Alex 'print (name [3]) # Slice print (name [0: 3] ''' name = 'I am moving like this, but you didn't respond to 'print (name [0: 8: -2]) ''' S = 'python's most Nb 'print (s [: 3]) print (s [2]) print (s [6:]) print (s []) print (s [1:]) print (s [: 6: 2]) print (s []) print (s [:]) print (s [3: 2]) print (s [-5:-3]) ''' # For Loop name = 'long sasao' for I in name: Print (I) # S = Len (name) # obtain the total length of a string # print (s) ''' COUNT = 0 while count <Len (name): Print (name [count]) Count + = 1 '''
I. integer 1. Relationship between digit size and bit. bit_length # How to query the digits? Boolean (bool) and numeric conversion true falsen = bool (6) Output True? # Can numbers and boolean values be converted to each other? INT (true) Output 1 #? CAN numbers and boolean values be converted to each other ?, During conversion, only zero is false, and the rest are true # When the Boolean value is converted to a number, true is 1false and 0 is ?? # When converting a string to a Boolean value, if it is not empty, it is true2. detailed explanation of the string:. Title # The title makes the first letter uppercase ?? Only when special characters are separated can they be considered as multiple words. (Chinese characters are also special characters. capitalize is capitalized, regardless of the number of words in the string, only the first letter is capitalized. upper () makes all letters in the word uppercase. lower? () Make all letters in the word lower case. Count () count?. Find () Search location ?, If the search does not exist,-1. Index () is returned. If the search does not exist, an error is returned. Center? () Place the first digit in the center, and the second digit in the content to be filled. Split () # split? When there is no input in the brackets, the default space is to split the strings by cutting the characters in the brackets, and put the separated strings in a list for output. # You can convert a string to a list. strip () # Remove spaces and line breaks at both ends by default ??. What is the beginning and end of the deleted content? Application Scenario: when a user logs in, the error caused by spaces in the password account can be eliminated .. join () # specifies the character concatenation? S = Name. replase ('x', 'n') # Replace the first one with the replaced content, and the second one with the replaced content ?? Name. startswith () # What does the computer start ?, The obtained result is a Boolean name. endswith () # ask at what end the obtained result is a Boolean value. format () # format the content in the brackets into the variable {}:? # Can be filled according to the placeholder position? # You can also fill the field by index # according to the corresponding keyword? Is series methods :?. Isalnum? () # Determine if it is a number or letter. isalpha? () # Determine whether it is a pure letter. isdigit () # determine whether it is a pure number. isupper () # determine whether it is a capital letter. islower (# determine whether it is a lowercase letter? # Remove spaces when a user logs on: press Ctrl + C to copy the code and press Ctrl + C to copy the Code # Use Cases of upper and. Lower :? The verification code is used for a long time :? YZM = 'o98k': copy the code y_zm = input ('Enter the verification code o98k: ') If y_zm.upper () = YZM. Upper (): Print (' correct! '?? Else: Print ('error') Copy code subscript (INDEX): m e t 0 1 2 3 ?? -4-3-2-1 slice; [start position: end position: Step Size] the head and tail are switched from left to right: [] from right to left: [-1: -4:-1]? The following 1 and-1 refer to the direction, where + refer to left-to-right and-refer to right-to-left. the second colon indicates the step size. # interview question: If you say "I am above, but you didn't respond below", the output name = "I am above, but you didn't respond below" Print (name [: :-1]) # indicates the overall output when the start position is not written # interview question: how to convert a string to a list through a line of code ??, At the same time, convert the list to a string using a line of code? Using method. Split (). Join () to convert and copy code name = 'Alex 'print (name. Split ())? LST = ['1', '2', '3'] S = '_'. Join (LST )?? Copy code ?? For Loop (traversal loop) for (keyword) + I (variable) + in (keyword) + iteratable object ??? (Except that numbers are all iteratable objects )? A For Loop is a finite loop. The number of loops depends on the number of elements in the iteration object. copy the code as needed #-*-coding: UTF-8-*-# convert numbers to boolean values ''' n = bool (1) print (n) N0 = bool (0) print (N0) n00 = bool (-1) print (n00) n1 = int (true) print (N1) N2 = int (false) print (N2) ''' # number of digits ''' n = 600 print (N. bit_length () ''' # Use '''name = 'Alex uwu Sir 'print (name. center (15, '*') # center, place the character in the middle, and add the preceding number to print (name. split ('U') # split the string by cutting the characters in the brackets, meanwhile, put the split string in a list and output S = '_'. join (n AME) # insert, insert _ to print (name. replase ('A', 'I') # Replace. The previous content is replaced, and the subsequent content is print (name. startswith () # ask what the variable starts with print (name. endswith () # ask the variable at what end print (name. count ('W') # Count print (name. title () # print (name. capitalize () # print (name. lower () # print (name. upper () # print (name. find ('M') # output-1 print (name. index ('l') # index. If the index does not exist, the following error occurs: ''' # formatting ''' name = '{2}. {1} {0}'s. = Name. format ('xx ', 'fucking', 'pretty ') # print (s) S1 = Name. format ('xx ', 'fucking', 'pretty ') print (S1) name1 = '{A} {B} {c} 's2 = name1.format (A = 'xx', B = 'fucking ', c = 'pretty ') print (S2) ''' # Remove space ''' name = 'Alex 'print (name. strip () user = input ('enter account :'). strip () Pwd = input ('Enter the password :'). strip () If user = 'Alex 'and Pwd = 'alex3714': Print ('entered correctly') else: Print ('entered incorrectly ') ''' # verification code example ''' YZM = 'os98k' Y _ ZM = input ('input Verification Code o98k: ') If y_zm.upper () = YZM. Upper (): Print ('correct! ') Else: Print ('error') ''' # how to convert a string to a list using a line of code ??, At the same time, convert the list into a string using a line of code: '''name = 'Alex wumsp' print (name. split ('s') lst = ['1', '2', '3'] S = '_'. join (name) print (s) ''' # determine whether it is a pure number. The output data type is '''num = input ('enter a number: ') If num. isdigit (): num = int (Num) print (type (Num) else: Print ('all tell you the number ') ''' # subscript index''' name = 'Alex 'print (name [3]) # Slice print (name [0: 3] ''' name = 'I am moving like this, but you didn't respond to 'print (name [0: 8: -2]) ''' S = 'python's most Nb 'print (s [: 3]) print (s [2]) print (s [6:]) print (s []) print (s [1:]) print (s [: 6: 2]) print (s []) print (s [:]) print (s [3: 2]) print (s [-5:-3]) ''' # For Loop name = 'long sasao' for I in name: Print (I) # S = Len (name) # obtain the total length of a string # print (s) ''' COUNT = 0 while count <Len (name): Print (name [count]) Count + = 1 '''
Character conversion details and preliminary understanding of For Loop