python3学习手册★字符串.format()格式化函数 建议使用 "字符串".format(argxx) 的新式字符串格式化函数,返回格式 化后的字符串 .format()通过将strxx字符串中的{}来识别替换字段 {字段名!转换字段:格式说明} print( "我叫{},年龄{}岁".format("李", 20) ) ①字段名 ★可省,就写{},默认从左到右对应后面.format()里的arg xxx .format()里传入tuple参数时,得带上*号,如: cof = ("李", 20) print("我叫{0},年龄{1}".format( *cof) ) 传入dic�onary时,得带上**双星号 传入类的对象时,不带星号,在{}里取对象的属性 a = classx("李", 20) print("我叫{0.name},今年{0.age}".format(a)) 传入list 传入list,tuple,dic�onary时,若不想按顺序取值,可用.[i]按下标取值 a=[1,2,3] print("我{0.[1]},在{0.[0]}里".format(a)) ②转换字段 !s 把参数str()一下,即调用str()去格参数 !r repr() !a 返回ascii(),或\unnnn \xnnnn0 码力 | 213 页 | 3.53 MB | 1 年前3
A Seat at the Table - IT Leadership in the Age of Agilityinsightful? What do you think of the Agile for Defense Meetup group as a whole? Do you like the format? Are there other formats you have seen at other Meetup groups that might be worth trying? On the0 码力 | 7 页 | 387.48 KB | 5 月前3
共 2 条
- 1













