Python basic data type (-)

Source: Internet
Author: User

Digital

int (integral type)

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

Boolean value

True or False 1 or 0

String

1  . S. Capitalize ()----First letter capitalized

 1 s="Lifei"2print(S.capitalize ()) -------  Lifei

2. S.center (width, fillchar=none)----Content Center, Width: total length, Filchar: Front and back blank content fill

s="Lifei" print(S.center ("^")) ------ ^^ ^^ ^^ ^lifei^ ^^ ^^ ^^ ^

S.ljust (width, fillchar=none)-------left-aligned, right-filled

s="Lifei" print(S.ljust ("^")) ------lifei^ ^^ ^^ ^^ ^^ ^^ of ^^ ^^

S.rjust (width, fillchar=none)-----Right-aligned, left-padded

s="Lifei" print(S.rjust ("^")) -----^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ Lifei

S.count (Sub, start=none, End=none)------Number of subsequence

s="Lifei" print(S.count ('i', 0,2) ) ------1 (Lifei in I appear several times from left to right greater than or equal to 0 less than 2)

4. s.endswitn (suffix, start=none, end=none)-----Whether to end with * * *

s="Lifei" print(S.endswith ('i', 0,3)) --- ---False (end of Lifei with I ending from left to right greater than or equal to 0 less than 3)

5.s.expandtabs (Tabsize=none)------Turn the TAB key into a space, and the default tab key equals 8 spaces

s="Li\tfei" print(s.expandtabs )------Li Fei (set tab \ t equals 20 spaces)

6.s.find (Sub, Start=none, End=none)-------looking for a subsequence, if not found, returns-1

s="Lifei" print(s.find ('i', 0,3)) ----- 1 (from left to right greater than or equal to 0 less than 3 find I find return 1, cannot find return-1)

S.rfind (Sub, start=none, End=none)------Looking for a subsequence, if not found, returns-1

s="Lifei" print(s.rfind ('i', 0, 3) ) -----1 (from right to left greater than or equal to 0 less than 3 find I find return 1, cannot find return-1)

S.index (Sub, Start=none, End=none)-------looking for a subsequence, if not found, error

s="Lifei" print(S.index ('i', 0,2)) -----1

S.rindex (Sub, start=none, End=none)------Looking for a subsequence, if not found, error

s="Lifei" print(S.rindex ('i', 0,3 )) ----1

7.s.format (*args, **kwargs)-----string Formatting

s="Lifei {0}, Age{1}" print(S.format ('hello'), 20)) #{0} placeholder ------Lifei hello,age20 (hello instead of {0},20 instead of Age{1})

8.s.isalnum ()-----contains letters or numbers, returns true, otherwise False

s="lifei1" print(S.isalnum ()) ------True

S.isalpha ()----All letters, returns TRUE, otherwise False

s="Lifei" print(S.isalpha ()) -------True

S.isdigit ()----All are numbers, return true, otherwise False

s="1lifei" print(S.isdigit ()) ----False

9.s.islower ()-----is lowercase, returns true, otherwise False

s="Lifei" print(S.islower ()) -----True

10.s.isspace ()----Whether it is a space

s="Lifei" print(S.isspace ()) -----False

11.s.istitle ()----Determine if it is a title (all uppercase letters are headings)

s="Lifei" print(S.istitle ()) -----False

12.s.isupper ()---Determine if all uppercase

s="Lifei" print(S.isupper ()) ------True

13.join (self, iterable)------connection

li=["l","H"] #列表
Li= ("1", "H") #元祖 print("_". Join (LI))------L_h

14.s.lower ()----uppercase letters to lowercase

s="Lifei" print(S.lower ()) ------Lifei

S.upper ()------Lowercase to uppercase

s="Lifei" print(S.upper ()) ------Lifei

15.s.lstrip (chars=none)------Remove left space

s=" Lifei " print(S.lstrip ()) -----Lifei

S.rstrip (chars=none)------Remove the right space

s=" Lifei " print(S.rstrip ()) -------Lifei

S.strip (chars=none)------Remove both spaces

s=" Lifei " print(S.strip ()) ------Lifei

16.s.partition (Sep)------segmentation, the first and last three parts (primitive type)

s=" Lifei " print(s.partition ('f')) ----(' Li ', ' f ', ' ei ')

S.rpartition (SET)-----segmentation, the last three parts (primitive type)

s="Lifei" print(s.rpartition (i)) ----(' life ', ' I ', ')

17.s.replace (old, new, count=none)------Replace

s=" Lifei " print(s.replace ('i',' a')) -----LAFEA (i replace a)

18.s.rsplit (Sep=none, Maxsplit=none)------The last three parts of the split (the split character disappears) from the right

s="Lifei" print(s.rsplit ('i')) ------[' L ', ' Fe ', ']

Split (Sep=none, Maxsplit=none)-------the last three parts of the split (the split that character disappears) from the left

s="Lifei" print(s.split ('e')) -----[' Lif ', ' I ']

19.s.splitlines (Keepends=false)------Split by line break

s="Lifei\nlifei" print(S.splitlines ()) -----[' Lifei ', ' Lifei ']

20.s.startswith (prefix, start=none, end=none)------Determine if a character begins

s="Lifei" print(S.startswith ('L')) ----True

S.swapcase ()-----Uppercase to lowercase, lowercase to uppercase

s="Lifei" print(S.swapcase ()) -----Lifei

22.s.title ()------content into a title

s="my name is Lifei" print(S.title ()) -----My name is Lifei

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.