Python basics 3 -- string, python3 -- string

Source: Internet
Author: User

Python basics 3 -- string, python3 -- string

String

 

1. case-insensitive Conversion

1 >>> name 2 'bigint' 3 >>> name. capitalize () # capital 4 'bigberg '5 >>> name 6 'bigberg' 7 >>> name. casefold () # Replace all uppercase characters with lowercase 8 'bigberg '9 10 >>> name. upper () # All characters are capitalized 11 'bigint' 12 >>> name. lower () # All characters in lower case 13 'bigberg'

2.

1 'bigberg '2> name. center (20, '-') # center, 20 characters long 3 '------ bigberg ------- '4 5 >>> name. find ('B') # search for characters. If the index exists, the first index is returned. If the index does not exist, the system returns-1 6-1 7 >>> name. find ('B') 8 0 9 >>> name. find ('G') 10 211 12 >>> name. endswith ('sd') # character 13 False14 at the end of the query> name. endswith ('G') 15 True

3. Determine the string type

1 >>> name. isalpha () # whether it is a string 2 True 3 >>> name 4 'bigberg '5 >>>. isalpha () 6 False 7 >>> a 8 '000000' 9 >>>. isdigit () # whether it is an integer 10 True11 >>>. isnumeric () # whether all are numbers 12 True13 14 isspace # whether it is a space 15 is. upper () # whether it is all uppercase 16 is. lower () # whether it is all lowercase 17 18 >>> name # convert all uppercase and lowercase 19 'bigberg '20 >>> name. swapcase () 21 'bigberg'

4. join ()

1 >>> "-".join(['123','456','789'])2 '123-456-789'

 

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.