1.
#使用给定宽度打印格式化后的价格列表
width = int(input('Please enter width:'))
price_width = 10
item_width = width - price_width
header_format = '% - *s%*s' <span style="background-color: rgb(204, 204, 204);"> <span style="color:#ff0000;">宽度是用户输入信息,不能硬编码,用*可以从转换元组中读出字段宽度,-表示左对齐数值 </span></span>
format1 = '% - *s%*.2f'
print('=' * width)
print(header_format % (item_width, 'Item', price_width, 'Price'))
print('-' * width)
print(format1 % (item_width, 'Apple', price_width, 0.4))
print(format1 % (item_width, 'Pears', price_width, 0.5))
print(format1 % (item_width, 'Cantaloupes', price_width, 1.92))
print(format1 % (item_width, 'Dried Apricots(16 oz.)', price_width, 8))
print(format1 % (item_width, 'Prunes(4 lbs.)', price_width, 12))
print('=' * width)
2. join (连接序列中的元素) , lower, replace(替换) , split(join的逆方法), strip(去除两侧空格), translate( 单个字符的替换)
3. string.capwords(s[, sep]) 使用split函数分割字符串s(以sep为分隔符),使用capitalize函数将分割得到的各单词首字母大写,并且使用join函数以sep为分隔符将个单词连接起来
string。maketrans(from,to) 创建用于转换的转化表