实验2 字符串和列表

x1, y1 = 1.2, 3.57
x2, y2 = 2.26, 8.7
# 输出1
print('{:-^40}'.format('输出1'))   
print('x1 = {}, y1 = {}'.format(x1, y1))
print('x2 = {}, y2 = {}'.format(x2, y2))
# 输出2
print('{:-^40}'.format('输出2'))   
print('x1 = {:.1f}, y1 = {:.1f}'.format(x1, y1))  
print('x2 = {:.1f}, y2 = {:.1f}'.format(x2, y2))
# 输出3
print('{:-^40}'.format('输出3'))  
print('x1 = {:<15}, y1 = {:<15}'.format(x1, y1)) 
print('x2 = {:<15}, y2 = {:<15}'.format(x2, y2))

s=input('请输入一个字符串:')
s=s.upper()
s=s.replace('A','')
print(s)

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']
name_list=sorted(name_list)
n = 1
for name in name_list:
     print(f'{n}: {name.title()}')
n+=1
实验5

实验六


总结
需反复练习,熟悉lower(),upper(),append(),insert(),remove()等的用法

 



 

 

 

posted @ 2021-04-07 20:33  玮光溢彩  阅读(97)  评论(1)    收藏  举报