Magic Day10 for Python strings

Source: Internet
Author: User

Capitalize first letter

" Alex "  = test.capitalize ()print(v)

All lowercase, the first is a lot better, many unknown correspondence can be changed to lowercase

Test/casefold ()

Test.lower ()

Set the width, and put the text in the middle, 20, for total length, and X for blank padding

" ALEX "  =test.center ("x")print(v)

Calculates the number of elements in the current text count,a represents the found element, 5, 6 for the beginning and end

" Alexaler "  =test.count ("a", 5,6)print(v)

Whether to end with what Shartwith start with what

" Alexaler "  =test.endswith ("a")print(v)

Find a character in the string position, get the first position, regardless, 5,8 indicates from where to, to find must be greater than the location, can not find the same -1,index function, but can not find an error

" Alexaler "  =test.find ("R", 5,8)print(v)

formatting, replacing placeholders in strings with established values

 test =  al{ex}al{ex}  " 
#括号可替换为0,
#下面则不用ex =, write directly rprint (test) v =test.format (ex=" r " ) print (v)
" Al{0}al{1} " # brackets can be replaced by 0,1,2 # The following is not ex=, write directly R Print  =test.format ("R","D")  Print(v)

Determines whether the string contains only letters and numbers

" uasf890+ "  = test.isalnum ()print(v)

Magic Day10 for Python strings

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.