String manipulation:
#!/usr/bin/env python# -*- coding: utf-8 -*-# author:jack niuname = "My \tname is {name}" #加入一个tab键的空格print (Name.capitalize ()) Capital Letter print (Name.count ("a")) # How many aprint in the string (Name.center (50, "-")) #长度50, in the middle, two times-padded print (Name.endswith ("Cke")) #是否以cke结尾print ( Name.expandtabs (tabsize=30)) #30的tabsiziprint (Name.find ("is") #查找is的第一个字母的indexprint (Name.format_map ( {" Name ": " Niubin "} )") #替换print ("1 A". Isalnum ()) #是否是阿拉伯数字 + Arabic character print ("Sssaa". Isalpha ()) #是否是英文字母print ("10" . Isdecimal ()) #是否十进制print ("Ten". IsDigit ()) #是否是数字print ("a10a". Isidentifier ()) #判断是不是一个合法的标识符, variable name print ("a10a". Islower ()) #是否是小写print ("3333". IsNumeric ()) #是否是数字print (" ". Isspace ()) #是否是空格print ("My name is jack ". Istitle ()) #是否是titleprint (" My name is jack ". Isprintable ()) #是否能打印, some files cannot be printed print (" My name is jack ". Isupper ()) #是否大写print (", ". Join ([" 1 ", " 2 ", " 3 " ]) # #1, 2, 3 Add comma print ("My name is jack") in the middle. Ljust (50, "*")) #长度50, left * padded print ("My name is jack". Rjust (50, "-")) #长度50, right-padded print ("my Name is jack ". Lower ()) #把大写变成小写print (" My name is jack ". Upper ()) #把小写变成大写print (" my Name is jack ". Replace (" My ", " my ", 1)) #把小写变成大写, replace print (" alex ". Lstrip ()) # Remove the left space and enter print ("alex ". Rstrip ()) #去掉右边的空格和回车print (" Alex ". Strip ()) #去掉左边和右边的空格和回车p = Str.maketrans ("abcdef", "123456") print ("Alex li". Translate (p)) #将alex li Replace with the corresponding character in 123456 print ("1+ 2+3 ". Split (" + ")) #以加号切片print (" 1+2\n+3+4 ". Splitlines ()) #以换行符切片print (" Alexli ". Swapcase ()) #全部转换为大小写反向print (" My name is jack ". RFind (" name ")) #print (" My name is jack ". Zfill ()) #在前边补0
Python Learning record-2016-12-20