# -*-coding:UTF-8-*-
def basic_operator():
# * + 操作
str1 = 'hello'
str2 = 'python'
print(str1 + ' ' + str2) # hello python
print(str1 * 2 + ' ' + str2 * 2) # hellohello pythonpython
# 原始字符串输出
str3 = 'pytho\n'
str4 = r'pytho\n'
print(str3) # pytho 换行
print(str4) # python
# 格式化字符串
print('I am %s, I am %d years old' % ('张三', 100)) # 当用%格式化字符串时要用元组
print('I am {:s}, I am {:d} years old'.format('张三', 10))
# 对其格式化
print('id'.ljust(10) + 'name'.ljust(10) + 'score'.ljust(10))
all_info = [['12345678', 'Tom', 88], ['12345679', 'Jerry', 78.5]]
for info in all_info:
print('{:10s}{:10s}{:.1f}&#
Python3菜鸟教程(4):字符串的操作和内置函数
最新推荐文章于 2022-10-14 18:38:17 发布