Python string, list, tuples, set, dictionary method, python string

Source: Internet
Author: User
Tags iterable

Python string, list, tuples, set, dictionary method, python string
List

1. L. append (object)-> None

Add a single element at the end of the list. Any type is acceptable, including list or tuples.

 

2. L. extend (iterable)-> None

Add multiple elements at the end of the list in sequence

 

3. L. insert (index, object)-> None

Add an element at the index position

 

4. L. clear ()-> None

Clear all elements in the list to become an empty list

 

5. L. copy ()-> list

Get a list copy

 

6. L. count (A)-> integer

Returns the number of times A appears in the list.

 

7. L. index (A, [start, [stop])

Returns the position where A appears for the first time in the list. You can specify the start and end positions. Note: [start, end)

 

8. L. pop ([index])-> integer

The element at the corresponding position is displayed. If no parameter is specified, the last element is displayed by default.

 

9. L. remove (A)-> None

Delete the first element A. Other elements A are not good

 

10. L. sort (key = None, reverse = False)-> None

Sort the list in ascending order by default. If reverse = True, it is changed to descending order. You can pass a function to the key parameter, such as lambda or pre-defined function. Then, define the sort based on the function, for example, the last number or the number after the dashes below.

This method changes the list sorting.

 

11. L. reverse ()-> None

Sort the list in descending order

This method changes the list sorting.

 

Tuple

1. T. count (A)-> integer

Returns the number of times A appears in the ancestor.

 

2. T. index (A, [start, [stop])-> integer

Returns the position where A appears for the first time in the ancestor. You can specify the start and end ranges. Note: [start, end)

 

 

Set

1. S. add (element)-> None

Add an element to the set

 

2. S. clear ()-> None

Clear all elements of a set

 

3. S. copy ()-> set

Returns the copy of the original set.

 

4. S. remove (element)-> None

Removes an element from the set. If the element is not in the Set, an error is returned.

 

5. S. discard (element)-> None

Same as above, but if this element is not in the Set, no error is reported.

 

6. S. pop ()-> element

A random element of the original set is displayed.

 

7. S. isdisjoint (S2)-> bool

Returns True if there is no intersection between the two sets.

 

8. S. issubset (S2)-> bool

Returns True if the S2 (sequence or set) set contains the S set.

 

9. S. issuperset (S2)-> bool

Returns True if the S set contains S2 (sequence or set ).

 

10. S. difference_update (S2)-> None

S minus the intersection of S and S2 (sequence or set), no value is returned,

This method will change the original set S

 

11. S. intersection_update (S2)-> None

The intersection of S and S2 (sequence or set) does not return any value,

This method will change the original set S

 

12. S. Metrics ric_difference_update (S2)-> None

The Union of S and S2 minus the intersection of S and S2. No value is returned.

This method will change the original set S

 

13. S. update (S2)-> None

The Union of S and S2 (sequence or set) does not return any value,

This method will change the original set S

14. S. intersection (S2)-> set

Returns the intersection of S and S2 (sequence or set ).

 

15. S. difference (S2)-> set

Returns the intersection of S minus S and S2 (sequence or set ).

 

16. S. tricric_difference (S2)-> set

Returns the Union of S and S2 minus the intersection of S and S2. S2 can be a sequence or set.

 

17. S. union (S2)-> set

Returns the Union of S and S2 (sequence or set ).

 

Dictionary dict

1. D. clear ()-> None

Clear all key values in the dictionary

 

2. D. copy ()-> D

Returns a dictionary copy.

 

3. D. pop (k [, d])-> value

The corresponding k key value is displayed, and the key value is removed. If the k key is not found but the value of d is set, the value of d is returned. If the value of D is not set and the k key is not found, an error is returned.

 

4. D. popitem ()-> (k, v)

A key value pops up in the form of a parent (usually the first key value of the stack)

 

5. D. keys ()-> a set-like object

All keys have been returned in the form of similar lists (in fact, they are returned more like objects in the class list and will not process repeated values)

 

6. D. values ()-> a set-like object

All values have been returned in the form of a similar list (in fact, the returned object is more like a list of classes and does not process repeated values)

 

7. D. items ()-> a set-like object

All key values have been returned in the form of a similar list, and each key value is returned in the form of a parent (in fact, the returned object is more like a list of classes and does not process repeated values)

 

8. D. get (k [, d])-> D [k] if k in D, else d.

If the dictionary has k keys, the corresponding value is returned. If the dictionary does not exist but the value D is entered, the value D is returned. Otherwise, the return value is null.

 

9. D. setdefault (k [, d])-> D. get (k, d), also set D [k] = d if k not in D

If the dictionary has k keys, the corresponding value is returned. If the dictionary does not exist, but the D value is entered, a new key value is created in the original dictionary and the value is returned. If the value D is not specified, the value corresponding to the k key is null.

 

10. D. update (D2)-> None

D2 is also a dictionary. Merges the key values of D2 into D. If the same key exists, D2 overwrites D.

This method will change the original dictionary D

 

11. D. fromkeys (iterable, value = None)-> dict

This method is used to create a dictionary. All elements of an object can be iterated as keys, and value can be unique values. Returns a multi-key-to-single-value Dictionary (regardless of whether D is empty or not)

 

String str

1. S. capitalize ()-> str

Converts the initial character to uppercase. Note that if the first character is not in uppercase, the original string is returned.

 

2. S. upper ()-> str

Uppercase of all letters in the original string

 

3. S. lower ()-> str

Lowercase letters in the original string (only A-Z in ASCII code can be completed)

 

4. S. casefold ()-> str

Lowercase letters in the original string (more objects can be identified and output in lower case)

 

5. S. swapcase ()-> str

Swaps the uppercase and lowercase letters in the original string.

 

6. S. replace (old, new [, count])-> str

Replacement character. The count parameter represents the number of old characters to replace. If the count parameter is not specified, all old characters are replaced by default.

 

7. S. expandtabs (tabsize = 8)-> str

Replace all the tabs (\ t) in the string with spaces. The default number of replacement spaces is 7 (8-1, where tabsize = 0 indicates removing \ t, tabsize = 1 or 2 indicates a space, and the rest are n-1 spaces)

 

8. S. Fill ust (width [, fillchar])-> str

If the length of the original character is less than width, the remaining part is filled with spaces on the left. If a single character is filled in, use a character instead of a space. (Note: Only single characters are allowed)

 

9. S. ljust (width [, fillchar])-> str

Same as above. But fill it on the right.

 

10. S. center (width [, fillchar])-> str

Same as above. However, both sides are required. Fill in the remaining part on the right.

 

11. S. zfill (width)-> str

If the length of the original character is less than width, the remaining part is filled with 0 on the left.

 

12. S. find (sub [, start [, end])-> int

Returns the position of the substring that appears for the first time in the original string. You can specify the start and end positions. If the substring is not in the original string,-1 is returned. Note: [start, end)

 

13. S. index (sub [, start [, end])-> int

Same as above, but if the substring is not in the original string, an error is returned. Note: [start, end)

 

14. S. rindex (sub [, start [, end])-> int

Same as index, but from the right to the left of the string, but returns the first character position on the leftmost of the substring

 

15. S. rfind (sub [, start [, end])-> int

The same as find, but from the right to the left of the string, but returns the first character position on the leftmost of the substring

 

16. S. split (sep = None, maxsplit =-1)-> list of strings

Returns a list with the separator sep. Maxsplit indicates the number of times to be separated. The default value is "full ".

 

17. S. rsplit (sep = None, maxsplit =-1)-> list of strings

Same as above. But from right to left

 

18. S. splitlines ([keepends])-> list of strings

Returns a list of linefeeds as separators. The default keepends value is False, indicating the list. line breaks are removed from all the elements in the list. If it is set to True, the line break is retained.

 

19. S. partition (sep)-> (head, sep, tail)

This method is used to split strings Based on the specified delimiter. If the string contains the specified delimiter, a 3-element tuple is returned. The first is the substring on the left of the separator, the second is the separator itself, and the third is the substring on the right of the separator.

If the Delimiter is not specified, the first character is the original string, and the second three are null characters.

 

20. S. rpartition (sep)-> (head, sep, tail)

Same as above, but from right to left, and if it does not contain the specified separator, the first two are null characters, and the second is the original string

 

21. strip ([chars])-> str

By default, a string that removes spaces between the left and right sides is returned. If the parameter is a subcharacter, remove all the subcharacters on both sides.

 

22. S. rstrip ([chars])-> str

Same as above, but only remove the characters on the right

 

23. S. lstrip ([chars])-> str

Same as above, but only remove the characters on the left

 

24. S. startswith (prefix [, start [, end])-> bool

Determines whether the string starts with a string. If yes, True. You can specify the start and end positions.

 

25. S. endswith (suffix [, start [, end])-> bool

Same as above, but the end is judged

 

26. S. count (sub [, start [, end])-> int

Returns the number of times the substring appears in the original string. You can specify the start and end positions.

 

27. S. join (iterable)-> str

Fill the original character with the elements of the sequence

 

28. S. encode (encoding = 'utf-8', errors = 'strict ')-> bytes

Encoding. Many errors parameters are available, including 'ignore'

 

29. S. isidentifier ()-> bool

Whether it is a Python keyword or not. If it is True

 

30. S. isalnum ()-> bool

Whether the string is composed of digits, English letters, or Chinese characters (including roman numerals). If it is True

 

31. S. isdecimal ()-> bool

Whether the string contains only 10-digit numbers

True: Unicode number, full-angle number (dual-byte)

False: Roman numerals, Chinese numerals

Error: byte number (single byte)

 

32. S. isnumeric ()-> bool

Whether the string contains only numbers

True: Unicode, full-angle (dual-byte), roman numerals, and Chinese characters

False: None

Error: byte number (single byte)

 

33. S. isdigit ()-> bool

Whether the string contains only numbers

True: Unicode number, byte number (single byte), full-byte number (double byte), and Roman numerals

False: Number of Chinese Characters

Error: None

 

34. S. isspace ()-> bool

Whether the string contains only spaces (spaces, tabs, line breaks). If it is True

 

35. S. isalpha ()-> bool

Whether the string contains only letters. If it is True

 

36. S. islower ()-> bool

Whether all the letters in the string are lowercase (can contain non-letter characters). If it is True

 

37. S. isupper ()-> bool

Returns True if all letters (including other content, such as numbers) in the original string are uppercase.

 

38. S. isprintable ()-> bool

Whether all characters in the string are visible (for example, \ n is invisible). If it is True

 

39. S. istitle ()-> bool

Whether or not the first letter of each word in the character is capitalized (except letters in the character, only available and normal punctuation characters are allowed), if it is True

 

40. S. maketrans (x, y = None, z = None)-> dict

41. S. translate (table)-> str

Refer to the preceding statement (the table here refers to the dictionary ing table)

 

42. S. format_map (mapping)-> str

Note: The key cannot be a pure number.

 

43. S. title ()-> str

The first letter of each word in the character is capitalized (various characters are allowed to be separated in the middle)

 

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.