>>>favorite_language = 'python '
#右边有空白
>>> favorite_language.rstrip() 'python'
你还可以剔除字符串开头的空白,或同时剔除字符串两端的空白。为此,可分别使用方法lstrip()
和strip()
age = 23
message = "Happy " + age + "rd Birthday!" print(message)
#it is wrong because age is not string
message = "Happy " + str(age) + "rd Birthday!"
将一条消息存储到变量中,将其打印出来;再将变量的值修改为一条新消息,并将其打印出来。
message = "Hello Python Crash Course reader!"
print(message)
message = "hahaha"
print(message)
The result is
Hello Python Crash Course reader!
hahaha