The second thing Python walks up

Source: Internet
Author: User

Python Basics

One, integer (int)

such as: 18, 73, 84

Functional methods and examples of integer classes:

The method with __ represents a variety of expressions

1.__ABS__ <==> ABS ()

To find the absolute value of an integer: ( -11). __abs__ () <==> ABS (-11) with a result of 11

2.__add__

Sum of integers: (ten). __add__ <==> 10+10, the result is 20

3.__divmod__

Divide, get quotient and remainder tuple: x.__divmod__ (y) <==> divmod (x, y)

Here are just a few examples of common methods.

Two, long plastic, floating point

Long plastic such as: 2147483649, 9223372036854775807

Floating-point numbers such as: 3.14, 2.88

Functional methods are similar to integers.

Three, string

such as: ' Xigang ', ' Jack '

1.capitalize (self)

"" "Capitalize the first letter" ""

' Xigang '. Capitalize ()---> ' Xigang '

2.center (self, width, fillchar=none)

"" "Content centered, Width: total length; Fillchar: padding content in white space, default None" "

' Xigang '. Center (+, ' * ')--*******xigang*******

3.count (self, sub, Start=none, End=none)

"" "Number of sub-series" ""

' Xigang '. Count (' G ')--2

4.endswith (self, suffix, start=none, end=none)

"" "whether to end with XXX" "

' Xigang '. EndsWith (' G ')---True

5.expandtabs (self, tabsize=none)

"" To convert the tab to a space, the default one tab to 8 spaces "" "

' \txigang '. Expandtabs (tabsize=4) and Xigang

6.find (self, sub, Start=none, End=none)

"" "to find the sub-sequence position, if not found, return-1" ""

' Xigang '. Find (' ng ')--4

7.format (*args, **kwargs)

"" "string format, dynamic parameter" ""

' Name {0} {name} '. Format (' is ', name= ' Xigang ')--name is Xigang

8.index (self, sub, Start=none, End=none)

"" "sub-sequence position, if not found, error" ""

' Xigang '. Inxdex (' n ')--4

9.isalnum (self)

"" "is the letter and number" ""

' Xigang123 '. Isalnum ()---True

10.isalpha (self)

"" "is the letter" ""

' Xigang123 '. Isalpha ()--flase

11.isdigit (self)

"" "is the number" ""

' 123 '. IsDigit ()---True

12.islower (self)

"" "Whether lowercase" ""

' Xigang '. Islower ()--flase

13.isspace (self)

"" "is a Space" ""

". Isspace ()---True

14.istitle (self)

"" "Whether the first letter is uppercase, the title" ""

' Xigang '. Istitle ()---True

15.isupper (self)

"" "Whether uppercase" ""

' Xigang '. Isupper ()---True

16.lower (self)

"" "Change lowercase" ""

' Xigang '. Lower ()--Xigang

17.lstrip (self, chars=none)

"" To remove left margin "" "

' Xigang '. Lstrip ()--' Xigang '

18.rstrip (Self,chars=none)

"" Remove right Blank "" "

19.strip (Self,chars=none)

"" To remove the left-hand margin "" "

20.replace (self, old, new, Count=none)

"" Replace "" "

' Xigang '. Replace (' XI ', ' XI ')--Xigang

21.split (self, sep=none, Maxsplit=none)

"" "Split, maxsplit up to several times" "

' Name is Xigang '. Split ()--[' name ', ' is ', ' Xigang ']

22.splitlines (self, keepends=false)

"", Split by line break "" "

Iv. List

such as: [11,22,33], [Xigang ', ' Jack ']

1.append (self, p_object)

add Element "" "at End of List" "

a= [11,22,33]

A.append ()--[11,22,33,44]

2.count (self, value)

The number of occurrences of "" "Element" ""

a= [11,22,33,44,11]

A.count (one-off)-2

3.extend (self, iterable)

"" "Two list Merge" ""

A=[11,22,33]

B=[' A ', ' B ', ' C ']

A.extend (b)--[11,22,33, ' A, ' B ', ' C ']

4.index (self, value, Start=none, Stop=none)

"" Displays the index value for value "" "

A=[11,22,33]

A.index (1)

5.insert (self, Index, p_object)

Insert index and value "" in the list

A=[11,22,33]

A.insert (1, ' Xigang ')--[One, ' Xigang ', 22,33]

6.pop (self, index=none)

The value "" "of the index is removed from the list

A=[11,22,33]

A.pop (2)--[11,22]

7.remove (self, value)

"" In the list, delete the element "" "

A=[11,22,33]

A.remove ()--[11,33]

8.reverse (self)

The position of the element in the list is reversed "" "

9.sort (self, cmp=none, Key=none, Reverse=false)

Sort the elements in the list "" "

Five, the tuple

such as: (11,22,33), (' Xigang ', ' Jack ')

1.count (self, value)

The number of occurrences of the element "" "in the Tuple" ""

2.index (self, value, Start=none, Stop=none)

The index value for the element in the tuple "" "

VI. Dictionary

such as: {' name ': ' Xigang ', ' Age ': 18}, {' Host ': ' 2.2.2.2 ', ' Port ': 80]}

1.clear (self)

"" Clears all elements in the dictionary "" "

2.copy (self)

"" "Shallow Copy" ""

3.get (self, k, d=none)

"" Gets the value according to key, D is the default value "" "

4.has_key (self, k)

"" "Whether there is a key" ""

5.items (self)

"" List form for all items "" "

6.keys (self)

"" "All Key List" ""

7.pop (self, key, D=none)

"" To Get and remove "" in the Dictionary

8.popitem (self)

"" Randomly removes a key value "" "

9.setdefault (self, k, d=none)

"" If key does not exist, then create, if present, return the existing value and do not modify "" "

10.update (self, e=none, **f)

"" "To add a dictionary to the specified dictionary" "

Dict = {' Name ': ' Xigang ', ' age ': +}

Dict1 = {' Job ': ' It '}

Dict.update () Dict1---{' Name ': ' Xigang ', ' age ': ' job ': ' It ' }

11.values (self)

"" "List of all Values" ""

The second thing Python walks up

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.