【第二章答案】 习题 2-3 a = "wang_ming_xin" b = "Hello " +a+ ", would you like to learn some python today" #不要忘了 +a+ ,c语言C++中也会有这样的用法 print(b)
# 习题 2-4 a = "wang ming xin" b = a.upper() print(b) c = a.lower() print(c) d = a.title() print(d)
# 2-5 print('Guangwudi: "where there is a will,there is a way."') # 光武帝说的 # 2-6 famous_person = 'Guangwudi' message =( ': "where there is a will,there is a way."') print(famous_person + message) # 2-7 打印人名、 name = '\twang\nsijiang\t' print(name) a = name.rstrip() print(a) b = name.strip() print(b) c = name.lstrip() print(c) #2-8 print(2+6) print(2*4) print(16/2) print(10-2) # 2-9 a = 6 #print(a+ "is my favorite number") # #会报错 TypeError: unsupported operand type(s) for +: 'int' and 'str' print(a.__str__()+ " is my favorite number!")# 先把a转换成字符串