以下的都是在Python3.X环境下的
使用 input 函数接收用户的输入,返回的是 str 字符串
最简单的打印
>>print("hello,word!")
hello,word!
打印数字
>>a=5
>>b=6
>>print(a)
>>print(a,b)
>>print(a+b)
5
5 6
11
打印字符
>>a="hello,"
>>b="world!"
>>print(a,b)
>>print(a+b)
hello, world!
hello,world!
特别注意,当字符串是等于一个数的时候,这样两个字符串相加还是字符串。要把字符串转化为数字类型的才可以使用相加
>>a=input("请输入第一个数字:") #20
>>b=input("请输入第二个数字: ") #10
>>print(a,b)
>>print(a+b)
>>print(int(a)+int(b))
20 10
2010
30
字符串的格式化输出
>>name="小谢"
>>age="20"
>>print("{}的年龄是{}".format(name,age))
>>print("%s的年龄是%s"%(name,age))
小谢的年龄是20
小谢的年龄是20