Related methods for the "Python string" string (i)

Source: Internet
Author: User
Tags true true

---restore content starts---

Capitalize () method to capitalize the first letter of the string

# Convert the first letter of a string to uppercase Text = ' Alet 'ret = text.capitalize () print (ret) 
Alet

  

Casefold () method to capitalize the first letter of the string

# converts all uppercase letters of a string to lowercase ' Alet '  = text.casefold ()print(ret)
Alet

Centers A string and fills the Text.center ()

# Set the width and center the content # 10 represents the total length of the string # * represents blank position padding (one character allowed) ' Alex '  = Text.center (+,'*')print(ret)

Count occurrences of characters (' ex ', 1,5)

Text.count (' character to Judge ', ' index of Start position ', ' index of End position ')

# calculate the number of occurrences of a character ' Alexalex '  = Text.count ('ex')print(ret)
2

  

Determine whether to start with what, ending with StartsWith () EndsWith ()

# decide whether to start with, what to end with ' Alexalex ' startret=text.startswith ('al'= Text.endswith ('ex  ')print(Startret,endret)
True True

  

---restore content ends---

Related methods for the "Python string" string (i)

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.