您现在的位置是:网站首页> 内容页

python字符串拼接相关

  • www.bm7779.com
  • 2019-03-26
  • 267人已阅读
简介#字符串拼接#str.join(元组、列表、字典、字符串)之后生成的只能是字符串。str="-";seq=("a","b","c");#字符串序列sqr=["a","

#字符串拼接#str.join(元组、列表、字典、字符串) 之后生成的只能是字符串。str = "-";seq = ("a", "b", "c"); # 字符串序列sqr=["a","b","c","sss"]#listssr=str.join(sqr)print("=".join(ssr))

print (str.join(sqr));print (str.join(seq));

seq = {"hello":"nihao","good":2,"boy":3,"doiido":4}#对象print("-".join(seq))

#打印字符print ("His name is %s"%("Aviad"))#1. 打印字符串#http://www.cnblogs.com/plwang1990/p/3757549.htmlprint ("He is %d years old"%(25))#2.打印整数print ("His height is %f m"%(1.83))#3.打印浮点数print ("His height is %.2f m"%(1.83))#4.打印浮点数(指定保留小数点位数)print ("Name:%10s Age:%8d Height:%8.2f"%("Aviad",25,1.83))#5.指定占位符宽度print ("Name:%-10s Age:%-8d Height:%-8.2f"%("Aviad",25,1.83))#6.指定占位符宽度(左对齐)print ("Name:%-10s Age:%08d Height:%08.2f"%("Aviad",25,1.83))#7.指定占位符(只能用0当占位符?)

文章评论

Top