1. "{},{}". Format (,) Usage Summary:
' {0},{1} '. Format (' var1 ', 132908) ' var1,132908 ' {},{} '. Format (' var1 ', 132908) ' var1,132908 ' {0},{1},{1},{0} '. Format ( ' Var1 ', 132908) ' Var1,132908,132908,var1 '
2. Keyword parameters:
' {name},{age} '. Format (age=18,name= ' Wangchao ') ' wangchao,18 ' class Person:def __init__ (self,name,age): Self.name, Self.age = Name,agedef __str__ (self): "Return ' this book was {self.name},is {self.age} old". Format (self=self) print person (' Wangdage ', () This book is Wangdage,is oldp=[' Wanghhao ', [] ' {0[0]},{0[1]} '. Format (P) ' wanghhao,18 '
3. "%s"% () Form:
Print "I ' m%s. I ' m%d year old "% (' cobe ',") I ' M cobe. I ' m the year Oldprint "I ' m% (name) s. I ' m% (age) d year old "% {' name ': ' Coolbe ', ' age ': 99}i ' m coolbe. I ' m a year old
Summarize:
In addition to the built-in % operator, Python can be used for formatting string operations, as well as "". Format () requires proficiency in the form of
Big talk python formatted output string