Python String function Learning

Source: Internet
Author: User

1. Center

' Colum ' Print (Name.center,'*')

View Code

Fill in the middle of the content, the effect is ******colum*******

2.Count

Calculate the number of input parameters

' Colum ' Print (Name.count ('u'))

3.decode Decoding encode encoding

4.Expandtabs

Change the tab to a space, or you can use \ t to replace a space

' He is        2*tab'print(Name.expandtabs ())

He is 2*tab

5.Find Index

Find the parameters and return to the location. Find return failure also has a value of -1, index lookup failed to return an error

' He is        2*tab'print(name.find ('2'7
Print (Name.find (' 3 '))
-1

Print (Name.index (' 3 '))
Valueerror:substring not found

6.Join

Connection string

' He is        2*tab'print("_". Join (name)) H_e_ _i_s_    _    _2_*_t_a_b

7.partition

Split the content into three parts, with the parameter as the middle

' He is        2*tab'print(name.partition ('2')) ('  He is\t\t'2'*tab' )

8.replace

Replace

' He is        2*tab'print(name.replace ('2','3  'is        3*tab

9.split

Split return list, default space split

' He is        2*tab'print(name.split ('*')) ['  He is\t\t2'tab']

10.strip

The default is to remove the space at both ends of the line, the parameter is remove content

' 22112   He is        2*tab  2'print(Name.strip ('2'))            2*tab  21  

Python String function 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.