共计 739 个字符,预计需要花费 2 分钟才能阅读完成。
#encoding: utf-8
#tuple 元组值不可变
# nums = (1,2,3,4,)
# print(type(nums))
# print(nums[-1])
a ,b =(1,2,)
print(a)
# nums_1 = (213,2,2131231,5,)
# print(nums_1 + (3,2,1,))
# print(nums_1 * 2)
# print(nums_1)
#占位符 % %s 字符串 %d 数字 %f 浮点型
print('name:%s,age:%d,money:%f' %('caoguojian',28,10.23))
# %3s 占 3 个字符右对齐 - 3 左对齐
print('name:%s,age:%3d' %('caoguojian',28))
# %02d 向右对齐时,左边填充 0
print('name:%s,time:%02d' %('caoguojian',4))
#不建议使用 %,使用 format 函数, 值可以重复使用
print('我叫:{0},{1}岁, 是的我 {1} 岁了,money:{2}'.format('caoguojian',28,10.23))
#也可以使用需要的类型或者多少个占位
print('我叫:{0},{1}岁, 是的我 {1:5d} 岁了,money:{2:f}'.format('caoguojian',28,10.23))
#默认是右对齐,左对齐 {1:<5d},居中对齐{1:^6d},填充{2:05d} 默认右对齐
print('我叫:{0},{1:^6d}岁, 是的我 {1:<5d} 岁了,money:{2:05d}'.format('caoguojian',28,10))
#浮点型保留小数点后 2 位数{0:10.2f}
print('money:{0:10.2f}'.format(28.1214))
正文完