Python datatype notes

Source: Internet
Author: User
Tags decimal to hex ord pow type null

Data type in Python # Standard type: Numeric string list meta-ancestor dictionary other types: type Null file Collection function/method Class Number: Properties: 1. Only one value can be stored 2. Once defined, cannot be changed 3. Direct Access categories: Shaping, Long Integer, Boolean, floating point, complex python3 in long integer Unity for shaping Boolean: True and False floating-point numbers float:1.2e-5=0.0000121.23* 109=1.23e9 the built-in function of the number: int: When the passed-in parameter is a decimal, the fractional part int (3.5) 3round is stripped away: rounded to take the decimal round (3.5) 4math.floor:; like int Take away the number nearest but smaller than the nearest but greater than the original decimal Math.ceil (3.1) 4long: Long Plastic factory function float: floating-point factory function complex: Complex factory function bool: Boolean factory function The incoming parameter is non-null, non-0 non-none returns Trueabs : ABS ( -1) 1coerce: Accepts two parameters, turns data into the same type, returns a meta-ancestor coerce ( -1,3.2) ( -1.0,3.2) Divmod: Returns the progenitor, containing quotient and remainder Divmod (93,10) (9,3) POW: Take the Square pow (2,3,3) equivalent to 2**3%3 2 pow (2,3) equivalent to 2**3hex (hexadecimal): Decimal to Hex hex (Ten) = ' 0xa ' Oct (octonary): Decimal to octal Oct (10) = ' 012 ' Ord: Converts a character to decimal ord (' a ') according to ASCII =97CHR: Converts decimal into character chr (' =a ') based on ASCII definition: It is a set of ordered characters used to store representations of basic textual information "or" or "" "" " are string attributes: 1. Can only hold one value of 2. Immutable 3. The character set is defined in order from left to right, and the subscript is sequentially accessed from 0 in order 4. The single and double quotation marks of a string cannot suppress the meaning of special characters, and if you want all the characters in the quotation marks to nonspacing the special meaning needs to be preceded by R R ' L\THF ' 5.unicode string with R must be preceded by R as: Name=ur ' L\THF ' focus remove blank: Strip () split: Split () Length: Len () Index: Index () Slice: string[1:2] String Manipulation str.capitalize () The initial uppercase str.casefold () Casefold function recognizes more objects to output them aslowercase, while the lower function can only complete uppercase-to-lowercase conversions between A-Z in ASCII codes str.center (Width[,fillchar]) word Fu hollow complement Str.count (Sub[,start[,end]]), int A range of statistics on the number of occurrences of a str str.startswith/endswith () begins to end Str.find (Sub[,start[,end]])->intstr.index (Sub[,start[,end]])- >intstr.isalnum (), bool at least one character, and all letters or numbers return Truestr.isalpha ()->bool at least one character, and all Letters return Truestr.isdecimal () Whether the bool string contains only the decimal character str.isdight (), whether the bool string is all numeric Str.isidentifier ()->bool is the identifier in Python str.islower ()/isupper () Whether the case Str.isnumeric ()->bool is only composed of numbers str.space (), whether it is a space str.istitle (), whether it is a caption (capital letter) Str.join ( iterable) string joins an iterative object Str.ljust/rjust (Width[,fillchar]) similar to center, respectively, left-to-right str.split (Sep=none, Maxsplit=-1) to split the string, Specifies that Sep is a delimiter and maxsplit is the maximum delimiter.  0 means no split, 1 means split into 2 segments Str.splitlines ([Keepends]): Keepends is true, means reserved \ n, false not reserved str.replace (old, new[, Count]) Replace the count of old for the new new,count default for all str.swapcase () converts the case of each letter in the string # Print (1.3e-3) # print (1.3e3) #二进制 10/2print (Bin (10)) # Octal 10/8 12print (Oct) #十六进制 0-9 a b c d e fprint (hex) # name=input ("Username ") # print (type (name)) # Name=name.strip () # #去掉左右2边的字符 #x= ' ********egon********** ' # x=x.strip (' * ') # print (x) #x = ' Hello ' # print (X.capitalize ()) # Print (X.upper ()) # Print (X.center (' + ', ' # ')) #居中显示 # Print (X.count (' l ', 0,3)) print ( X.startswith ()) print (X.endswith ()) msg= ' name:{},age:{},sex:{} ' msg1= ' name:{0},age:{1},sex:{0} ' msg2= ' Name:{x},age : {y},sex:{z} ' Print (Msg.format (' Egon ', ' $, ' mail ')) print (Msg1.format (' aaaaa ', ' bbbb ')) print (Msg2.format (x= ' Egon ', y =18,z= ' Male ') print (X.find (' e ')) x= ' Hello World ' print (x[0]) print (x[4]) print (x[5]) print (x[100]) #超出范围print (X[-1]) Print (x[-3]) print (X[1:3]) print (X[1:5:2]) #步长x = ' Hello ' Print (x.index (' o ')) print (x[4]) print (X[x.index (' O ')]) x= ' 123 ' Print (X.isdigit ()) Age=input (' Age: ') if Age.isdigit (): New_age=int (age) Print (New_age,type (new_age)) msg5= ' Hello Alex ' Print (Msg5.replace (' x ', ' x ')) Print (Msg5.replace (' l ', ' n ')) print (Msg5.replace (' l ', ' A ', 2)) x= ' root:x:0::0:/ Root:/bin/bash ' Print (X.split (': ')) x= ' Hello ' Print (X.upper ()) x= ' Hello ' Print (X.isupper ()) print (X.lower ()) Print(X.islower ()) x= ' Print (X.isspace ()) #全是空格 # Print (X.islower ()) # Print (X.isspace ()) x= ' abc ' Print (X.ljust (' x ')) # Left-aligned print (X.rjust (x, L ')) #右对齐 # Print (x.ljust) # Print (X.replace ()) # Print (X.split ()) msg= ' Hello ' Print (Msg.title ()) Print (Msg.istitle ()) x= ' AB ' Print (X.swapcase ()) need to master msg= ' Hello ' remove blank msg.strip () split msg.split () Length len (msg) Index Msg[0:5:2] "" "msg= ' Hello ' #移除空白print (Msg.strip ()) msg1= ' Root:x:0::0:/root:/bin/bash ' #分割print (Msg1.split (': ')) #长度print (Len ( MSG1)) #索引print (msg1[3]) #切片print (Msg[0:5:2]) #0 2 4x= ' *******egon******** ' Print (X.strip (' * ')) y= ' Hello ' #首字母大写print ( Y.capitalize ()) #所有字母大写print (Y.upper ()) #居中显示print (Y.center ($, ' $ ')) #统计某个字符个数print (Y.count (' l ')) print (Y.count (' l ', 0,4)) #0 1 2 3print (Y.startswith (' h ')) Print (Y.endswith (' e ')) #字符串格式化msg1 = ' name:{},age:{},gender:{} ' print ( Msg1.format (' Egon ', ' Male ')) msg2= ' name:{0},age:{1},gender:{0} ' Print (Msg2.format (' Morgana ', +)) msg3= ' name:{x} , age:{y},gender:{z} ' Print (Msg3.format (y=18,x= ' Egon ', z= ' Male ')) #字符串切片z = ' Hello World ' print (z[0]) #print (z[100]) #报错Print (Z[1:5:2]) #0 1 2 3 4a= ' Hello ' Print (a.index (' o ')) print (a[4]) print (A[a.index (' O ')]) # age=input (' Input your age ') # If Age.isdigit (): # New_age=int (age) # Print (New_age,type (new_age)) msg4= ' Hello Alex ' Print (Msg4.replace (' x ', ' X ')) Prin T (Msg4.replace (' l ', ' A ', 2)) b= ' Hello ' Print (B.isupper ()) print (B.islower ()) print (B.isspace ()) print (B.istitle ()) Print (B.swapcase ()) print (B.title ()) #左对齐print (B.ljust, ' * ') #有对齐print (B.rjust (), ' * ') c= ' Ab ' #反转print ( C.swapcase ())

  

Python datatype notes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.