第一周作业b 第2章选做(2、4、7、8、11)

2-2多条简单消息

temp="This is a string."
print(temp)

temp=123456
print(temp)

tip:变量不需要声明,直接使用,而且该变量的数据类型可以在程序运行过程中改变。


2-4调整名字的大小写

name="taylor swift"
print(name.title())
print(name.upper())
print(name.lower())


2-7剔除人名中的空白

name="\t\nBen\t\n"
print(name)
print(name.lstrip())
print(name.rstrip())
print(name.strip())

tip:该函数不修改变量内容


2-8数字8

print(3+5)
print(2*4)
print(16//2)
print(9-1)

tip:除法“/”在python3里会输出浮点数,即8.0,要输出整型,用“//”


2-11Python之禅

import this


猜你喜欢

转载自blog.csdn.net/cjf16337023/article/details/79518885
今日推荐