Python basic data type (i)

Source: Internet
Author: User

1. Digital int

The application environment for integers is mostly computational, so remember a function.

# bit_length () when decimal is represented in binary notation, the minimum number of bits used is v =one = v.bit_length ()print(data)
2. Boolean bool

There are two types of Boolean values: True,false. is the correct condition of the reaction.
True 1 true.
False 0 false.

3. String str3.1 Index and slice
A ='Rome Cold Day' #PS: Slice Gu Tou regardless of tailPrint(a[0:])#full forward output of the variable content 1Print(a[:])#full forward output of the variable content 2Print(A[0:5:2])#Forward plus stepPrint(A[5:0:-2])#Reverse Add stepPrint(A[::-1])#full reverse output of variable string Contents 1Print(A[-1::-1])#full reverse output of variable string contents 2Print(A[len (a)::-1])#full reverse output of variable string contents 3
3.2 Letter Conversion function
' Jason LV OR AAAA ' Print (A.capitalize ())   # The capitalize () function indicates that the first letter is converted to uppercase and the first non-letter is invalid. the print(A.swapcase ())     #swapcase () function represents the case conversion of letters in the entire string. the print(A.title ())        #title () function means that the first letter of the word in the entire string is converted to uppercase, and the non-initial letter is converted to lowercase.
Print (A.upper ()) #upper () function converts all letters to uppercase letters
Print (A.lower ()) #lower () function converts all letters to lowercase letters
3.3 Content Fill function
a0 = A.center (Len (a) + 2)   # Adds a space to the left and right of the string contents of variable A, then assigns a value to the variable a0a1 = A0.center ('* ')  # The Center () function means that the string content is centered on the length of the parameter and populated with the specified characters, and the default padding is a space.  Print(A1)
3.4 Element Statistic function
A2 = A.count ('a', 0,5)   #count () function supports slicing statistics based on element conditions to the number of elements in a string.  Print(A2,type (A2))      # return int
3.5Tab Fill function
' Ace\ta '  the = B.expandtabs ()   #expandtabs () function defaults to turning a TAB key into 8 spaces, and if the character in front of the tab is less than 8, the total is 8. If the character in front of the TAB key is longer than 8, then complete the 16, and so on, and then complete 8.  Print(B1)
3.6 Judging beginning and ending functions
' Adfwedfwsdfdsvcxcvdfwe '  = C.startswith ('df', 1,10)    #startswith () function to determine whether to .... Start print(C1)                       # Returns a Boolean value
C2 = C.endswith ('fw', 2,8)       #endswith () function to determine whether to .... At the end, the switching conditions follow Guxio regardless of the tail.  Print(C2)                       # Returns a Boolean value
3.7 Index Lookup function
C3 = C.find ('fw', 0,)       #the Find() function finds the specified number of indexes based on the element condition and cannot find the return-1;Print = C.index ('fw', 0,) # the index () function finds the specified number of indexes based on the element condition.          Unable to find the error;
3.8 Character Split function
C5 = c.split ('f', 2)     #split () function splits the string content according to the element condition, and supports the control of the number of splits. Finally, a list is returned with no split elements in the list.  Print(C5)
3.9 Formatting the output of the Format function
#three ways to format output of the Format function#The first type:Reg ='**************\n{} info show: \nname:{}\nage:{}\nhobby:{}'. Format ('Jason','Jason', 18,'pretty girl.')Print(REG)#The second KindReg ='**************\n{0} info show: \nname:{0}\nage:{1}\nhobby:{2}'. Format ('Jason', 18,'pretty girl.')Print(REG)#Third KindReg ='**************\n{name} info show: \nname:{name}\nage:{age}\nhobby:{hobby}'. Format (name ='Jason', age = 18,hobby ='pretty girl.')Print(REG)
3.10 Content Culling function
' *****ace** ' Print (Name.strip ('*'))  # the Strip () function rejects the variable by the condition the name string specifies the characters on both sides of the content Print (The Name.lstrip ('*'#lstrip () function rejects the variable by the condition of the name string to the left of the specified character Print (The Name.rstrip ('*'#rstrip () function rejects the variable on the right side of the name string, specifying the character
3.11 Detecting String Composition functions
' ABCdef123 ' Print (Name.isalnum ())   # detects whether a string consists of letters and numbers, returns a Boolean value Print (Name.isalpha ())   # detects whether a string consists of only letters, returns a Boolean value Print (Name.isdigit ())   # detects whether a string consists of only numbers, returns a Boolean value
3.12 Length Calculation function
' Oh, 123456789 . ' Print (len (name))    # returns the length of a string, list, Ganso, or number of items;
3.13 Replace function
' Jason LV is very NB '  = name.replace ('jason','Alex')    # replace () string content substitution function Print (name1)
4. Summary of functions

(1) The Capitalize () function indicates that the first letter is converted to uppercase and the first non-letter is invalid.
(2) the Swapcase () function represents the case conversion of letters in the entire string.
(3) the title () function indicates that the first letter of the word in the entire string is converted to uppercase, and the non-initial letter is converted to lowercase.
(4) The center () function indicates that the string content is centered on the length of the parameter and populated with the specified characters, and the default padding is a space.
(5) The count () function supports slicing statistics based on element conditions to the number of elements in a string.
(6) The Expandtabs () function defaults to a TAB key to 8 spaces, if the character length in front of the tab is less than 8, then complete 8, if the character in front of the TAB key is more than 8 less than 16, then complete 16, and so on each complement of 8.
(7) StartsWith () function to determine whether to .... Beginning
(8) EndsWith () function to determine whether to .... At the end, the switching conditions follow Guxio regardless of the tail.
(9) The Find () function finds the specified number of indexes based on the element condition and cannot find the return-1;
The index () function finds the specified number of indexes according to the element condition and cannot find an error;
(one) the split () function splits the contents of a string based on element conditions, supports controlling the number of splits, and ultimately returns a list that does not contain split elements.
Format formatted output function;
() The Strip () function rejects the specified characters on both sides of the contents of the variable name string based on the condition;
The Lstrip () function excludes the specified character on the left side of the contents of the variable name string based on the condition;
() the Rstrip () function rejects the specified character on the right side of the contents of the variable name string based on the condition;
() the Isalnum () function detects whether a string is composed of letters and numbers, and returns a Boolean value;
The Isalpha () function detects whether a string is composed only of letters and returns a Boolean value;
The IsDigit () function detects whether a string consists only of numbers and returns a Boolean value;
The Len () function returns the length of a string, list, Ganso, or number of items;

Python basic data type (i)

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.