Python's operations on strings

Source: Internet
Author: User

#-*-Coding:utf-8-*-
#Author: Gxli
#字符串的操作
Name= ' Zhangsan,lisi,wangwu '
#分割操作
Name=name.split (', ')
Print (name) #[' Zhangsan ', ' Lisi ', ' Wangwu ']
#列表转字符串拼接
Name= ' | '. Join (name)
Print (name) # ZHANGSAN|LISI|WANGWU


#去除开头结尾制定字符
Name2= ' LGX '
Name2=name2.strip () #name2 =name2.strip (")
Print (len (name2)) #3
#特殊显示
Print (Name2.center, '-') #------------------LGX-------------------
#查找字符并显示字符的下标
Print (Name2.find (' G ')) #1
#判断是否包含空格
Print ("in name2) #False
#首字母大写
Print (Name2.capitalize ()) #Lgx

#格式化显示
msg= "Hello, {name} it ' s been along {age}"
Msg2=msg.format (name= ' lll ', age=22)
Print (MSG2)
#isdigit () to determine whether a number
Age=input (' Your Age: ')
If Age.isdigit ():
Age=int (age)
Else
Print (' Invalid data type ')

#判断是否包含违法字符
name3= ' ALE3SDF '
Print (Name3.isalnum ())
#判断是否已dfsd结尾
Print (Name3.endswith (' DFSD '))
#判断是否已dfsd开头
Print (Name3.startswith (' DFSD '))
#大小写转换
Print (Name3.upper (). Lower ())


Python's operations on strings

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.