Python练习 2021/11/20 21:30
1.变量练习
x = “我真帅”
print(x)
2.将一个人名存储到一个变量中,再以小写、大写和首字母大写的方式显示这个人名。
name = "Ada"
print(name.upper())
print(name.lower())
3.名字拼接
first_name = "ada"
last_name = "smart"
full_name = first_name + " " + last_name
print("Hello, " + full_name.title() + "!")
# message = "Hello, " + full_name.title() + "!" 储存变量
4.使用制表符或换行符来添加空白 \t
print("Ada")
Ada
print("\tAda")
Ada #手动空白(doge)
5.换行符 \n
print("Hello:\nAda\nis\nsmart")
Hello:
Ada
is
smart
6.删除空白(主要是尾巴) rstrip()
favorite_language = 'python ' #n后面有空白,目标消掉空白
favorite_language = favorite_language.rstrip()
favorite_language
'python'
7.删除空白(开头&两端空白) lstrip()
favorite_language = ' python '
1. favorite_language.rstrip()
' python'
2. favorite_language.lstrip()
'python '
favorite_language.strip()
'python'