x1, y1 = 1.2, 3.57 x2, y2 = 2.26, 8.7 print('{:-^40}'.format('输出1')) # {:-^40}控制输出数据格式: 宽度占40列,居中对 齐,空白处用-补齐 print('x1 = {}, y1 = {}'.format(x1, y1)) print('x2 = {}, y2 = {}'.format(x2, y2)) # 输出2 print('{:-^40}'.format('输出2')) # {:-^40}控制输出数据格式: 宽度占40列,居中对 齐,空白处用-补齐 print('x1 = {:.1f}, y1 = {:.1f}'.format(x1, y1)) # {:.1f}控制小数输出精度,保留 1位小数 print('x2 = {:.1f}, y2 = {:.1f}'.format(x2, y2)) # 输出3 print('{:-^40}'.format('输出3')) # {:-^40} 控制输出数据格式: 宽度占40列,居中对 齐,空白处用-补齐 print('x1 = {:<15}, y1 = {:<15}'.format(x1, y1)) # {:<15}控制数据输出宽度占15 列,左对齐,空白处默认补空格 print('x2 = {:<15}, y2 = {:<15}'.format(x2, y2))
x=input() print(x.upper() .replace('A',''))
name_list = ['david bowie', 'louis armstrong', 'leonard cohen', 'bob dylan', 'cocteau twins'] n = 1 for name in name_list: print(f'{n}: {name.title()}') n += 1
name_list = ['david bowie', 'louis armstrong', 'leonard cohen', 'bob dylan', 'cocteau twins'] n = 1 for name in name_list: print(f'{n}. {name.title()}') n += 1
test='''The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those! ''' test1=test.splitlines() test2=len(test1) test3=len(test.split()) word=len(test.split())-test2+1 test4=test.count(' ') print(f'行数是{test2}') print(f'字符数是{test3}') print(f'单词数是{word}') print(f'空格数是{test4}')
print('{:-^50}'.format('我的愿望清单')) test=['不喜欢就说不','喜欢的事情就去做','上面的两个愿望可以实现'] n=1 for i in test: print(f'{n}.{i}') n=n+1