String, dictionary manipulation methods in Python

Source: Internet
Author: User

One, the string

In Python, a string is an important data type. Other data types are:

    1. The number-number-------- int, long, float, complex
    2. String-string-------- "Use quotation marks" are quoted as strings.
    3. Tuple-tuple------------elements enclosed in parentheses, separated by commas
      The above three is the immutable object in Python, the amount that cannot be changed after creation--the value that the variable points to memory cannot be changed, when a variable is changed, because its value cannot be changed, it is equivalent to copy the original value and then change, this will open a new address, The variable points to this new address again.
    4. List-list--------------- [1, 2, 3] [' A ', ' B ', ' C '] brackets, the elements inside are separated by commas
    5. Dictionary-dict-------------- {key1:value1, key2:value2} use curly braces + key-value method definitions, use between key values: colon, separate key pair values using commas
    6. Boolean-bool--------- true and False
      4, 5, 6 are mutable objects, meaning that the object points to the memory value can be changed.
1.1 Method of String
  1. str.capitalize()Will capitalize the first letter
  2. str.count(x, start=None, end=None)Counts the number of characters x specified in str, start and end as start and ending bits
  3. str.center(num, [指定字符])The STR string is centered in the num-length character and the second parameter is the padding character if the Str is not long enough. "{0:[填充字符]^[长度]}".format(str)the same effect
  4. str.endswith("tr")Determines if STR is a specified parameter, and here is the end of "TR", which returns True no false
  5. str.find([指定字符])Find the starting index of the parameter character in Str
  6. str.isalnum()Whether STR is an Arabic numeral, a character, is a return true
  7. str.isalpha()Is it pure English?
  8. str.isdecimal()is a decimal number
  9. str.isdigit()is an integer
  10. str.isidentifier()is a valid identifier (variable name)
  11. str.islower()Whether the string is all lowercase
  12. str.lower()Lowercase the string
  13. str.isupper()Whether the string is uppercase
  14. str.upper()Capitalize a string
  15. ‘[分隔符]‘.join([iterable])"+".join([‘1‘, ‘2‘, ‘3‘])the Join method argument as the result of the ' 1+2+3 ' delimiter is a recyclable object
  16. str.ljust(num, ‘[填充符]‘)Extended str length to num, not enough position to fill from right to left with padding
  17. str.split(sep=None)Splits a character by the Sep parameter and returns the split element as a list
  18. str.strip(chars=None)important The default is to remove space, \ n, \ t, or remove the specified parameter number from the string header and tail
>>> str_test = ‘\n/home/user/lina  

String, dictionary manipulation methods in Python

Related Article

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.