一、输入输出函数
1、print()函数
输出函数
向屏幕输出指定的汉字
print(“hello world”)
1
print()函数可以同时输出多个字符串,用逗号“,”隔开
print(“hello”,“how”,“are”,“you”)
1
print()会依次打印每个字符串,遇到逗号“,”会输出空格,输出的内容是这样的:
hello how are you
1
print()可以打印整数,或者计算结果
print(300)
300print(100 + 200)
300
1
2
3
4
我们也可以把打印的结果显示的再漂亮一些
print(“100 + 200 =”, 100 + 200)
100 + 200 = 300
1
2
注意:对于字符串”100 + 200 =”它会原样输出,但是对于100+200,python解释器自动计算出结果为300,因此会打印出上述的结果。
2、input()函数
输入函数
name = input()
jean
1
2
如何查看输入的内容:
name
‘jean’
1
2
或者使用:
print(name)
jean
1
2
当然,有时候需要友好的提示一下,我们也可以这样做:
name = input(“place enter your name”)
place input your name jeanprint(“hello,”, name)
hello, jean
3、int(”,2/8/16)转化为十进制函数(不带前缀)
二进制转为十进制
int(‘1010’,2)
10
1
2
八进制转为十进制
int(‘014’, 8)
12
1
2
十六进制转十进制