First, the basic number type
Numbers (shaping, long-shaped, floating-point, plural)
String
BYTE string: Describes the byte bytes type when introducing character encoding
List
Meta-group
Dictionary
Collection
Second, the number
Integral type and floating point type
# integer int role: Age, grade, social Security number, QQ number and other integer number related definitions: ages # Essence Age=int (Ten) # Float type float function: Salary, height, weight, physical parameters and other floating-point numbers related salary# essence salary=float (3000.3)# binary, Decimal, Octal, Hex
Other number types (understanding)
# long Plastic (learn) in Python2 (there is no concept of long shaping in Python3) : >>> num=2l >>> type (num )' long'># plural (learn) >>> x=1-2j >>> X.real 1.0 >>> x.imag -2.0
Three, string
# role: Name, gender, nationality, address and other descriptive information # definition: In single quotation marks \ double quotes \ Three quotation marks, consisting of a string of characters name='Egon'# precedence operation: value by index (positive fetch + in remove a blank strip split splitting loop
Other operations (including common)
#StripName='*egon**'Print(Name.strip ('*'))Print(Name.lstrip ('*')) #移除左变的指定字符Print(Name.rstrip ('*')) #移除右边的指定字符#Startswith,endswithName='ALEX_SB'Print(Name.endswith ('SB')) #以某个字符结尾Print(Name.startswith ('Alex')) #以某个字符开头#ReplaceName='Alex Say:i has one tesla,my name is Alex'Print(Name.replace ('Alex','SB', 1)) #修改指定字符#three ways to play formatres='{} {} {}'. Format ('Egon', 18,'male') #类似于占位符res='{1} {0} {1}'. Format ('Egon', 18,'male') #可以指定索引占位res='{name} {age} {sex}'. Format (sex='male', name='Egon', age=18) #指定变量占位#Find,rfind,index,rindex,countName='Egon Say hello'Print(Name.find ('o', 1, 3))#Gu Tou Regardless of the tail, can not find the return-1 will not error, found the display index#Print (Name.index (' e ', 2,4)) #同上, but could not find an errorPrint(Name.count ('e', 1, 3))#Gu Tou Regardless of the end, if you do not specify a range, find all#SplitName='Root:x:0:0::/root:/bin/bash'Print(Name.split (':'))#The default delimiter is a spaceName='C:/a/b/c/d.txt' #just want to get the top directoryPrint(Name.split ('/', 1)) name='A|b|c'Print(Name.rsplit ('|', 1))#start slicing from the right#Jointag=' 'Print(Tag.join (['Egon','say','Hello',' World']))#an iterative object must be a string#Center,ljust,rjust,zfillName='Egon'Print(Name.center (30,'-'))Print(Name.ljust (30,'*'))Print(Name.rjust (30,'*'))Print(Name.zfill (50))#Fill with 0#ExpandtabsName='Egon\thello'Print(name)Print(Name.expandtabs (1))#Lower,upperName='Egon'Print(Name.lower ())Print(Name.upper ())#Captalize,swapcase,titlePrint(Name.capitalize ())#Capitalize first letterPrint(Name.swapcase ())#Case Flipmsg='Egon say hi'Print(Msg.title ())#capitalize the first letter of each word#is Digital Series#in the Python3Num1=b'4' #bytesNum2=u'4' #no need to add U in Unicode,python3 is Unicodenum3='Four' #Chinese numeralsnum4='Ⅳ' #Roman Numerals#Isdigt:bytes,unicodePrint(Num1.isdigit ())#TruePrint(Num2.isdigit ())#TruePrint(Num3.isdigit ())#FalsePrint(Num4.isdigit ())#False#Isdecimal:uncicode#bytes Type No Isdecimal methodPrint(Num2.isdecimal ())#TruePrint(Num3.isdecimal ())#FalsePrint(Num4.isdecimal ())#False#Isnumberic:unicode, Chinese numerals, Roman numerals#bytes Type No Isnumberic methodPrint(Num2.isnumeric ())#TruePrint(Num3.isnumeric ())#TruePrint(Num4.isnumeric ())#True#Three cannot judge floating-point numbersnum5='4.3'Print(Num5.isdigit ())Print(Num5.isdecimal ())Print(Num5.isnumeric ())" "Summary: Most commonly used is isdigit, can judge bytes and Unicode type, this is also the most common digital application scenario if you want to judge Chinese numbers or Roman numerals, you need to use the IsNumeric" "#is otherPrint('===>') name='egon123'Print(Name.isalnum ())#strings consist of letters or numbersPrint(Name.isalpha ())#strings consist only of lettersPrint(Name.isidentifier ())Print(Name.islower ())Print(Name.isupper ())Print(Name.isspace ())Print(Name.istitle ())
Oldboy_python second day study record