码迷,mamicode.com
首页 > 编程语言 > 详细

python字符串拼接相关

时间:2018-08-17 00:40:18      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:元组   name   对象   html   生成   列表   log   height   宽度   

#字符串拼接
#str.join(元组、列表、字典、字符串) 之后生成的只能是字符串。
str = "-";
seq = ("a", "b", "c"); # 字符串序列
sqr=[‘a‘,‘b‘,‘c‘,‘sss‘]#list
ssr=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.html
print ("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当占位符?)

python字符串拼接相关

标签:元组   name   对象   html   生成   列表   log   height   宽度   

原文地址:https://www.cnblogs.com/tallme/p/9490848.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!