Python string manipulation

Source: Internet
Author: User

String manipulation

#!/usr/bin/env python
#-*-Coding:utf-8-*-

Name =' Wang '
user =' WANG '
print (dir)#dir see which members of the class can use the

Print (type (name)) #显示使用的哪个类

result = name. __contains__ (' W ') #in
Print (Result)

result = name. capitalize () #首字母大写
Print (Result)

result = user. casefold () #大写字母变小写
Print (Result)

result= name. Center ("*") #长度是20. Fill with * number, center keyword
Print (Result)

lens = ' qwertsadgsdsfqweqwrwersdfdfasdasdqweqwe '

result = Lens.count (' q ') #统计关键字的个数
Print (Result)

result = Lens. count (' Q ', 0,10) #统计关键字从0到10的个数
Print (Result)

Han = ' King '
result = Han. encode (' GBK ') #字符编码的转换
Print (Result)

result = lens. endswith (' we ') #判断字符串是否已什么结尾
Print (Result)

result = lens. endswith (' GS ', 1,10) #判断字符串从下标为1开始至下标为10的子串是否已关键字结尾
Print (Result)

Python string manipulation

Related Article

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.