Python---tuples

Source: Internet
Author: User

I. Tuple (tuple)

Tuples are similar to lists, but once created, they cannot be modified, so they are also called read-only lists.

Tuples have only two methods: Count & index.

eg. Names = ("Zhangsan", "Lisi")

See Yumbo Main Blog http://www.cnblogs.com/alex3714/articles/5717620.html

Two. strings (string)

Error Highlights

indentationerror:unexpected indent indicates indentation errors (which will be summed up later)

Name ="Xiaolaizi"2 Print(Name.capitalize ())#Capitalize first letter3 Print(Name.count ("I"))4 Print(Name.center (50,"-"))#print a total of 50 characters, not enough for "-" completion, name in the middle5 6 Print(Name.endswith ("Zi"))#you can tell what the ending is.7 " "8 name = "Xiao\tlaizi"9 Print (Name.expandtabs (tabsize=30))Ten " " One Print(Name.find ("Lai")) A Print(Name[name.find ("Lai"): 8])#strings can also be sliced
1info ="My name is {name} and I am {year} old!"2 Print(Info.format (name ="Xiaolaizi", year = 23))#formatted output3 Print(Info.format_map ({'name':"Xiaolaizi",' Year': 23}))#Format_map in dictionary format
info ="My name is {name} and I am {year} old!"a="Xiaolaizi"Print('AB4'. Isalnum ())#true is a letter or number is truePrint('ab4\f'. Isalnum ())#false contains special characters as falsePrint('AbM'. Isalpha ())#to judge the pure letter as true, including the casePrint('ox1a'. Isdecimal ())#Judging whether the decimal number or judging is not a decimal, I don't knowPrint('123'. IsDigit ())#Judging is not an integerPrint(A.isidentifier ())#the judgment is not a valid identifier (variable name)Print("Small". Isidentifier ())Print(A.islower ())#Judging is not lowercasePrint(A.isnumeric ())#similar to isdigit basic noPrint(" ". Isspace ())#Judging is not a spacePrint("My Name". Istitle ())#determine if the title (the first letter of each word is capitalized) TruePrint("My name". Istitle ())#FalsePrint("My Name". Isprintable ())#determine if a printable #tty file is not printable and seldom usedPrint("My Name". Isupper ())#judge whether all uppercase
View Code
"I" begins with:
info = "My name is {name} and I am {year} old!"
a = "Xiaolaizi"
print (' Ab4 '. Isalnum ()) #True is a letter or a number is true
print (' ab4\f '. Isalnum ()) #False containing special characters is false
print (' AbM '. Isalpha ()) # to judge the pure letter to be true, including case
print (' ox1a '. Isdecimal ()) #判断是不是十进制数 still judging is not a decimal, I don't know
print (' 123 '. IsDigit ()) #判断是不是整数
print (A.isidentifier ()) #判断是不是一个合法的标识符 (variable name)
Print ("small". Isidentifier ())
print (A.islower ()) #判断是不是小写
print (A.isnumeric ()) #类似于isdigit basic
print ("". Isspace ()) #判断是不是空格
print ("My Name". Istitle ()) #判断是不是标题 (capitalize the first letter of each word) True
print ("My name". Istitle ()) #False
Print ("My Name". isprintable ()) #判断是不是可打印的 #tty file is not printable and is seldom used
print ("My Name". Isupper ()) #判断是不是都大写

' J ' begins with:

Print('+'. Join (['1','2','3']))#Connect with +Print("'. Join (['Xiao','Lai','Zi'])) name="Xiaolaizi"Print(Name.ljust (25,'*'))#xiaolaizi**************** left to * replenish enough 30Print(Name.center (25,'*'))#********xiaolaizi********Print(Name.rjust (25,'*'))#****************xiaolaizi RightPrint('XIAO'. Lower)#Change LowercasePrint('Xiaolaizi'. Upper ())#XiaolaiziPrint('Xiaolaizi'. Strip ())#remove spaces or enterPrint('\nxiaolaizi'. Lstrip ())#Remove the left (blank) carriage returnPrint('Xiaolaizi'. Rstrip ())#Remove the space on the right

Print("Xiaolaizi". replace ('x','X'))#Replace XiaolaiziPrint("Xiaolaizi". RFind ('x'))#start looking from you, get the subscript from the left numberPrint("1+2+3+4". Split ('+'))#with "" Split extraction, return a list [' 1 ', ' 2 ', ' 3 ', ' 4 ']Print("Xiao Lai zi". Split (' '))#returns a list [' Xiao ', ' lai ', ' zi ']Print("Xiao\nlai\nzi". Splitlines ())#by line break [' Xiao ', ' lai ', ' zi ']Print("Xiaolaizi". Swapcase ())#casing upside down XiaolaiziPrint("Xiao Lai zi". Title ())Print("Xiao Lai zi". Title ())




Python---tuples

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.