Int int
python3, no matter how big numbers are of type int
python2 which has long integer long
The character string is converted into digital integer
# a='123' # print(type(a),a) # b=int(a) # print(type(b),b)
Note that if the floating-point number string is not cast an int type, and need to use floating point type float
# a='12.3' # print(type(a),a) # b=float(a) # print(type(b),b)
# Current number of bits at least n bits is represented by
age=3 r=age.bit_length() print(r)
# String type of built-in functions common usage
= the Test "ALAX" # v = test.capitalize () # capitalized, except for the first letter of the rest are in lower case, the data type of magic must function with parentheses print (v)
v1 = test.casefold () # string to lowercase # Print (V1) # V2 = test.lower () # Print (V2)
# Set the width and center the contents # Generation total length of 20 # * fill the amount Test = "Alex" V3 = test.center (20, '*') Print (V3)
# V = test.rjust (20, ' *') rjust specified number of characters to fill the right # print (v) # # V = test.ljust (20 is, '*') to fill the specified number of characters left ljust # print (v )
# String to find, to find occurrences sequence # to find the starting position may be provided # Test = "alaxxxx" # V = test.count ( 'X') # Print (V) # Test = "alaxxxx" # V = test.count ( 'x', 4,5 ) # of the second and third parameters are the start position and end position # print (v)
To what end # # what to begin with, if you find a specified character returns True, otherwise Flase # the Test = 'alex' # v = test.endswith ( 'EX', 2) # v1 = test.startswith ( 'Al' ) # Print (v1) # Print (v)
# Looking back from the beginning, after the first one found, acquiring its position, not found -1 Test = "alexalex" V1 = test.find ( "EX",. 5, 10) Print (V1)
# Format, a placeholder with the string specified value # = Test "the I AM {name}, Age {A}" # Print (Test) # V = test.format (name = "Alex" , a =. 19) # Print (V) # string to replace a placeholder value specified for # = Test "the I AM {0}, Age {}. 1" # Print (Test) # V = Test. the format ( 'Alex',. 19) # Print (V) # formatted incoming values { 'name': 'Alex,' a ':. 19} # = Test "the I AM {name}, Age {a}" test.format V = # (name = 'DF', A = 10) # Print (V) # V1 = test.format_map ({ 'name': 'DF', 'A':}. 19) # Print (V1)
# Index can not find the error, find the sub-sequence by the character string initial position # Test = "alexalexalex" # V = test.index ( 'EX') # Print (V)
# String contains only letters and numbers, if it is True, otherwise false # = the Test "uasf890_ +" # v = test.isalnum () # Print (v)
# Expandtabs, 20 punctuation, tab, must contain the string \ T Test = "123456aa \ T123 \ n789 \ T123" V = test.expandtabs (20) Print (V, len (V))
# Whether it is letters, Chinese characters # test = "as Don dr" # v = test.isalpha () # Print (v)
# The current input is a digital # the Test = "123②" # v2 = test.isdecimal () digital # v1 = test.isdigit () Digital ② # v3 = test.isnumeric () Digital ② two # print (v2, v1, v3 )
# Sensitive switch # Test = 'ALEX' # test.swapcase V = () # Print (V)
# Determines whether the string of letters, numbers, underscores: identifier # A = "_ 123" # V = a.isidentifier () # Print (V)
# Whether there is a non-displayable character # \ T tab \ n newline # Test = "hashh \ T111" # V = test.isprintable () # Print (V)
# Determine whether spaces are all # the Test = "" # v = test.isspace () # Print (v)
# Determine whether the title, or to turn him into the title, the title should be capitalized the first letter of # the Test = "at The futer the Return" # v = test.istitle () # v1 = test.title () # Print (v, v1)
# & **** the Join string elements in each of the specified delimiter splice # Test = "what you are the wind I" # Print (Test) # T = '' # V = t.join ( Test) # Print (V) # A = "B" # # B = "acdef" # V = a.join (B) # Print (V)
# Determines whether all lowercase, and all lowercase # Test = "Alex" # V1 = test.lower () # V2 = v1.islower () # Print (V1, V2) # determines whether all upper and all converted uppercase # v1 = test.isupper () # v2 = test.upper () # Print (v1, v2)
# Removes the specified string # limited matching up # Test = "xalex" # V = test.lstrip ( 'X') # V2 = test.rstrip ( 'XEA') # Print (V, V2)
# Remove about blank # the Test = "\ nalex" # test.lstrip () # test.rstrip () # test.strip () # v = test.lstrip () # v1 = test.strip () # Print (v, V1) # removed \ T \ n- # V = test.lstrip () # Print (V)
# Test = "aeiou" # test1 = "12345" # V = "funckududjjjcaaayuyiw" # m = str.maketrans (Test, test1) # new_v = v.translate (m) # string correspond replace
# print(new_v)
# Division String # Test = "testdsd" # V = test.partition ( "ST") # Print (V) # V = test.rpartition ( "S") containing a # Returns ancestral divided condition, can be divided into three sections # Print (V) # # V = test.split ( 'S', 2) does not contain a list # returns the division condition, the second parameter indicates the number of division condition # Print (V) # test.rsplit ( ) # regular expression # element if you want to divide
# Division, only segmentation based on new line, True, False: whether to keep the line breaks # the Test = "asdfasdf \ nasfdkks \ nikedkk \ nqkskk" # v = test.splitlines (False) # Print (v)
# Case conversion # Test = "ALEX" # V = test.swapcase () # Print (V)
# The specified character string with the first argument specifies a string to be replaced, the replacement string second argument, the third argument is the number of replacements Test = " alexalex " V = test.replace ( " EX " , " bb " , 1 ) Print (v)
String type commonly used built-in method
the Join ()
Split ()
Find ()
Strip ()
Upper ()
Lower ()
Replace ()
# method of operating a string
= Test " Syndrome horizons sister over here " # for cycle # for the variable name in a string # Print () COUNT = 0 the while COUNT < len (Test): Print (Test [COUNT]) COUNT + =. 1 Print ( " ++ +++++++++ " ) for Item in Test: Print (Item) # index, index, obtain a certain character string # Print (Test [0]) # slice v = test [0: 10] # 0 <= <10 V1 = Test [0: -1 ] Print (V, V1) # Python3 len obtain current string has several characters # Print (len (Test)) # len ( "dasg") character number # '_'. The Join ( 'aadss') # A = "anameljhshahljsljsj" # V = a.split ( 'l') of all default partition, may specify the number of points # Print (V) # Li = [11,22,33,44, 'sss'] #, division calculation # Print (len (Li) ) '' ' for slice loop index len ' '' Test = " Funck Come " # text corresponding index print test1 = INPUT ( " >>>> ") v = len(test1) for item in range(v): Print (Item, test1 [Item]) # for in the Test Item: # Print (Item) # BREAK # help create consecutive numbers, specified by setting a step discontinuity # v = the Range (0,10,5) # # v Item in for: # Print (Item)
Notes string
# String Once created, it can not be modified # Once modified or stitching, will result in re-creating a new string name = " hdshhs " Age = ' 18 is ' CNAME = name + Age Print (CNAME)