格式化类:%、format()
拼接类: +、()、join()
# 拼接并换行显示
import sys
print("\n".join(sys.path))
填值类:f-string
name = 'zaygee'
myname = 'python_test'
print("--------------格式化类----------------")
print('i am %s,i am studying %s' % (name, myname))
print("i am {0},i am studying {1}".format(name, myname))
print("-------------拼接类--------------------")
print(name + ' ' + myname)
list_info = ['zaygee', 'python']
print(' '.join(list_info))
print("-------------------填值类-------------------")
print(f'i am {name},i am studying {myname}')
#--------------格式化类----------------
#i am zaygee,i am studying python_test
#i am zaygee,i am studying python_test
#-------------拼接类--------------------
#zaygee python_test
#zaygee python
#-------------------填值类-------------------
#i am zaygee,i am studying python_test
字符串对齐方式
print("{:<10}".format("a")) # :< 为左对齐
print("{:>10}".format("a")) # :< 为右对齐
print("{:^10}".format("a")) # :^ 居中对齐
# a
# a
# a
for x in range(10):
# 不指定默认左对齐
print("{:2d} {:3d} {:5d}".format(x, x*x, x*x*x))
# 0 0 0
# 1 1 1
# 2 4 8
# 3 9 27
# 4 16 64
# 5 25 125
# 6 36 216
# 7 49 343
# 8 64 512
# 9 81 729