Python Data type Learning

Source: Internet
Author: User

    1. String type

Split splits a string by specifying a delimiter

Example:

Name = "Huang Zhong"

Print (Name.split ())

Strip remove character from string header and trailing, default space, Lstrip remove left character, Rstrip remove right character

Example:

Name = "Alex"

Print (Name.strip ())

Capitalize first letter to uppercase

Example:

Name = "Alex"

Print (Name.capitalize ())


Casefold all caps to lowercase, can convert multiple languages

Example:

Name = "AleX"

v = name.casefold ()

Print (v)


Lower all caps to lowercase, only English is converted

Example:

Name = "AleX"

v = name.casefold ()

Print (v)

Center text centered, padding with other characters in white space, padding by default blank character

Example:

Name = "Alex"

v = name.center (20, ' * ')

Print (v)


Number of occurrences of the count substring in the parent string

Example:

Name = "CNDKLSDNRFKNSV"

num = Name.count ("D")

NUM1 = Name.count ("D", 5) #从第5个索引开始计算

num2 = Name.count ("D", 5, 9) #计算从第5到第9之间d出现的次数

Print (num)

StartsWith whether to start with a character, or return true, otherwise false

Example:

Name = "Alex"

v = Name.startswith ("Al")

Print (v)


EndsWith whether to start with a character, or return true, otherwise false

Example:

Name = "Alex"

v = name.startswith ("ex")

Print (v)

Expandtabs Find tab and replace

Example:

Name = "Nsdl\tajnfcks\tsns"

v = name.expandtabs (#替换成20个字符), insufficient padding

Print (v)

Find finds the index position of the subsequence, not found return-1

Example:

Name = "Alex"

v = name.find ("o") #-1

Print (v)

Index finds the indexed position of the sub-sequence, no error found

Example:

Name = "Alex"

v = Name.index ("a")

Print (v)


format string Formatting

Example:

Name = v = Name.format (,,) (v) name = v = Name.format (=,=, =) (v)

Whether the isalnum is a number, a character, a Chinese character

Example:

Name = v = name.isalnum () (v) num = "two" V1 = Num.isdecimal () # ' 123 ' v2 = Num.isdigit () # ' 123 ' V3 = Num.isnumeric () # ' 123 ', ' two '

This article is from the "Linux Technology" blog, so be sure to keep this source http://xiaojishu.blog.51cto.com/4278020/1923283

Python Data type Learning

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.