字符串练习
练习2.3 个性化消息
name = 'eric'
text = 'would you like to learn some Python today?'
message = f"Hello {name.title()}, {text}"
print(message)
练习2.4 调整名字大小写
first_name = 'Key'
last_name = 'kilo'
full_name = f'{first_name} {last_name}'
print(full_name.title())
print(full_name.upper())
print(full_name.lower())
练习2.5 名言1
name = 'Albert Einstein'
saying = 'A person who never made a mistake never tried anything new.'
print(f'{name} once said, "{saying}"')
练习2.6 名言2
name = 'Albert Einstein'
saying = '"A person who never made a mistake never tried anything new."'
message = f'{name} once said, {saying}'
print(message)
或者
name = 'Albert Einstein'
saying = 'A person who never made a mistake never tried anything new.'
message = f'{name} once said, "{saying}"'
print(message)
练习2.7
name = '\n\tkilo\n '
print(name.lstrip())
print(name.rstrip())
print(name.strip())
练习2.8
filename = 'python_notes.txt'
simple_fname = filename.removesuffix('.txt')
print(simple_fname)
标签:saying,never,name,练习,print,字符串,message From: https://www.cnblogs.com/Key-Kilo76/p/string-practice-z2fw6bg.html