3rd Day of Python Learning

Source: Internet
Author: User

WordS= "Aleawusir"
S1=s.capitalize () #首字母大写
S2=s.upper () #全部变成大写
S3=s.lower () #全部变成小写
S4=s.swapcase () #大小写翻转
S5=s.title () #特殊字符或数字隔开 (capitalize the first letter of each separated word)
# s6=s.center (parameters, padding) #居中, default blank padding
Len (s) #判断长度
S7=s.startswith ("Al") #判断以什么为开头, the value returned is True,false
S71=s.startswith ("E", 2,5) #从2开始, ends at 5
S72=s.endswith ("W", 2,5) #判断以什么结束, the value returned is True,false
S8=s.find ("Z") #通过元素找索引 (subscript), cannot find return-1
S82=s.index ("a") #通过元素找索引 (subscript), unable to find an error
S9=s.strip ("element") #删空格 (front and rear), Rstrip (right), Lstrip (left)
S10=s.count ("A", 0,5) #查元素的个数
z= "SDSDS;DSDSD;SDSD;DSDSD"
L=z.split (";") #分割文本 (default space) returns the list str→list
Format ({}) #按照位置依次输出 the contents of a placeholder. Formatted output
S11=s.replace ("A", "B", 2) # (old text, new text, number of times) Replace text
Isalnum () Determines whether a string consists of letters or numbers
The Isalpha () string consists only of letters
The IsDigit () string consists only of numbers

msg= "" "
I am: {name}
How old am I: {age}
I am very handsome: {Henshuai}
"" " . Format (name =" Shong ", age=19,henshuai=" true ")
Print (msg)
msg= "" "
I'm l:{0}
How old am I: {1}
I am very handsome: {2}
"" " . Format (" Shong "," True ")
Print (msg)

msg= "" "
I am: {}
How old am I: {}
I am very handsome: {}
"" " . Format (" Shong "," Trer ")
Print (msg)


3rd Day of Python Learning

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.