Python Basic Data type

Source: Internet
Author: User
Tags arithmetic

1. Arithmetic operation:

2. Comparison operation:

3. Assignment Operation:

4. Logical Operation:

5. Member Arithmetic:

1, int

Python2 int has range, and long integer type
Python3 all the numbers are int no matter how long

On a 32-bit machine, the number of integers is 32 bits and the value range is -2**31~2**31-1, which is -2147483648~2147483647
On a 64-bit system, the number of integers is 64 bits and the value range is -2**63~2**63-1, which is -9223372036854775808~9223372036854775807
    • int is converted to int type, can be converted to such as "123a", default 10 binary
A = "123"
b = Int (a)
B = B + 1000

num = ("0011")
Int (num,base=2) 2 binary conversion

num = "a"
int (num, base=16) 16 binary conversion
    • Int.bit_length the binary of the current number at least in several representations
    • Range (0,100)
Python 2.7 is now created in memory
Python 3 optimization mechanism, for loop when creating in memory 2, Boolean bool
True or False 1 or 0 3, String str string once created non-modifiable, any modification will create a new copy of the string
methods to keep in mind:  
    1. Join () '. Join (String)
    2. Split ()
    3. Find ()
    4. Strip () according to the longest common sub-sequence
    5. Upper ()
    6. Lower ()
    7. The slice is indexed by the character string [0], the string [0:2]
    8. Len (String) string has several characters
    9. Iterate for variable name in string
    10. Replace replace a number of strings can be replaced with numeric parameters. Replace (string in old string, target substring, number of times)
Test = "Zzhou" # Initial capital print (Test.capitalize ())
# Turn lowercase, casefold more powerful can come out unknown correspondence print (Test.casefold ()) print (Test.lower ())
#center Set the width and center the content by 20-finger width, * The padding character can only have one # and the left padding ljust the right padding Rjust#zfill can be filled with only 0 print (Test.center (20, "*"))
#去字符串中寻找子序列出现的个数, starting position 5 End position 6 is optional print (Test.count ("zz", 5,6))
#以什么什么结尾起始位置5 End position 6 is optional print (Test.endswith ("ou", 5,6))
#以什么什么开头起始位置5 End position 6 is optional print (Test.startswith ("zz", 5,6))
#将tab符转换成空格, the default is 8, which returns a copy of the current string, preceded by a segmentation, and an insufficient bit of the previous one to complement print ("Z\thou". Expandtabs ()) print ("123456\t789". Expandtabs (6)) print ("1\t3456789". Expandtabs (6))
#find from the beginning, find the return index, cannot find return-1. [2,8] and only once #index can not find the error print (Test.find ("H", 2,8))
#format formatting, replace the placeholder print ("I am {name},age{a}") in order or name. Format (name= "Zhou", a=19)) print ("I am {0},age{1}". Format ("Zhou", 19) )
#format_map #format format print with a dictionary ("I am {name},age{a}". Format_map ({"Name": ' Weekly ', "a": 19})
#isalnum whether it is a letter and a digital print (Test.isalnum ())
#isalpha is the letter print ("abc"). Isalnum ())
Isdecimal IsDigit IsNumeric is the number isdigit more powerful such as "②" isnumeric support Chinese test = "123" V1 = Test.isdecimal () v2 = Test.isdigit () v3 = Te St.isnumeric () print (V1,V2)
Isidentifier is the legal identifier a = "str" Print (A.isidentifier ())
# isprintable whether there are non-visible characters such as \tprint ("Org\tsss") in the string. Isprintable ())
Print ("". Isprintable ())
#isspace () Whether all spaces #istitle () are headings each word is capitalized and can be used with the title () print ("Ni Shif eng Re". Title ()) #Ni SHIF Eng reprint ("Ni S HIF Eng Re ". Istitle ()) #True #*****************join () string each character is spliced by the specified delimiter ******************print (" ". Join (" I-I-i-Owen ")) #我 me I Owen Print ("&". Join ("I-I-i-Owen")) #我 & me & I & Euro & #islower () lower () judged to be lowercase converted to lowercase test = "Zhou" V1 = test.lower () v 2 = Test.islower () print (V1,V2) #isupper () Upper () determines that uppercase is converted to uppercase #lstrip () Rstrip () strip () remove left (\t,\r), right, all spaces can also be added to the parameter, Match as many characters as you need to remove


#S. Strip ([chars]) str

#Return a copy of the string S with leading and trailing
#whitespace removed.
#If chars is given and isn't None, remove characters in chars instead.

Test = "9lexxexa" v = test.rstrip (' xa ') print (v) #str. Maketrans ("abc", "123") ABC and 123 mappings Replace test = "Testaasa" #partition () split into three copies of Test.partition ("s") te S Taasa#rpartition () by string divided into three parts test.rpartition ("s") Testaa s A #split () test.split (' s ') te taa a can add a parameter to specify the number of splits, but s does not leave behind a regular expression #rsplit ()
#splitlines Split Print ("A\NB\NC") by line break. Splitlines (False) # = = ' A ', ' B ', ' C ' Print ("A\nb\nc". Splitlines (True)) # = = ' a\n ', ' b\n ', ' C ' #swapcase () case Conversion

  

Python Basic Data type

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.