python3-string manipulation

Source: Internet
Author: User

# Auther:aaron Fan

Name = "My \tname is {name}, and age was {age}."

‘‘‘
Print (Name.capitalize ()) #这段话的首字母大写
Print (Name.count ("a")) #统计这段字符串中一共有多少个a
Print (Name.casefold ())
Print (Name.center, "-") #一共打印50个字符, put the original string in the middle, both sides not enough with "-" to fill up
Print (Name.encode ()) #把字符串转换成二进制
Print (Name.endswith ("an")) #判断一个字符串以什么结尾, for example, returns True if ending with an, otherwise false
Print (Name.startswith (' my ')) #判断字符串是否以my开头
Print (Name.expandtabs ()) #把字符串中的tab转换成多个空格, converted to 30 spaces
Print (Name.expandtabs (tabsize=30)) #把字符串中的tab转换成多个空格, converted to 30 spaces
Print (Name.find ("name")) #返回字符串中第一个name的下标, the following example one of the slice usages
Print (Name[name.find ("Aaron"):])
‘‘‘
Print (Name.format (age=26,name= "Aaron Fan")) #format的具体用法在day1的interaction交互与字符串格式. Py There are examples in that script
Print ({' Age ': Name.format_map, ' name ': ' Aaron Fan ') #以字典的形式传送, the result is the same as format
Print ("123aBc". Isalnum ()) #判断字符串中是不是同时包含字母和数字, returns True if both letters and numbers are included, and no other spaces and any special characters are included.
Print ("Aaronfan". Isalpha ()) #判断字符串中是不是只有英文字母 returns True if there are only English letters and no other numbers, spaces, and any special characters.
Print ("123". Isdecimal ()) #判断是否为十进制
Print ("123". IsDigit ()) #判断是否为整数, this is used more, in the shopping cart that script has the use of examples, you can go to see
Print ("test123". Isidentifier ()) #判断是否为一个合法的变量名
Print ("123". IsNumeric ()) #判断是否只包含数字
Print ("\ t \ t". Isspace ()) #判断是否为空格
Print ("Aaron Fan". Istitle ()) #判断首字母是否全部为大写
Print (Name.isprintable ()) #判断这个东西是否可以打印, use it and check it out in detail.
Print ("AARON FAN". Isupper ()) #判断是否全部大写
#join的用法
List1 = ["1", "2", "3", "4", "5"]
Print ("+". Join (List1))

Print (Name.ljust, "*") #打印100个字符串, not enough words to the right of all with the specified characters to fill, here with *
Print (Name.rjust ("*")) #左边用 * Fill
Print ("Aaron FAn". Lower ()) #把大写变成小写
Print ("Aaron FAn". Upper ()) #把小写变成大写
Print (Name.lstrip ()) #去除左边的换行
Print (Name.rstrip ()) #去除右边的换行
Print (Name.strip ()) #去除两边的换行
#print (Name.maketrans ())
#print (Name.translate ())
#maketrans和translate加一起可以用来创建一个随机密码, with a rule of your own definition, check it out in detail.
Print ("Aaron Fan". Replace ("n", "n", 1)) #替换字符串中的指定字符, the example here is to replace one of the n, make it n, replace the value 1, or you can replace multiple
Print ("Aaron Fan". RFind ("n")) #从左网友数, find the subscript of the rightmost value
Print ("Aaron+fan". Split ("+")) #把字符串按照指定字符分成一个列表, by default separated by a space into a list
Print ("Aaron\nfan". Splitlines ()) #按照换行符, split the string into a list
Print ("Aaorn Fan". Swapcase ()) #把大写转小写, lowercase to uppercase
Print (Name.title ()) #所有单词的首字母都大写
Print ("123". Zfill ()) #不够100个数字, fill the front with zeros

#打印当前python使用的编码模式
Import Sys
Print (sys.getdefaultencoding ())

python3-string manipulation

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.