第一个python程序
输入和输出
1. 输出
//用print()在括号中加上字符串,就可以向屏幕上输出指定的文字
print("hello, world!")
//print()函数也可以接受多个字符串,用逗号“,”隔开,,会依次打印每个字符串,遇到逗号“,”会输出一个空格,因此,输出的字符串是这样拼起来的
print("hello","sherry","!")
hello sherry !
//print()也可以打印整数,或者计算结果
print(300)
300
print(100 + 200)
300
//我们可以把计算100 + 200的结果打印得更漂亮一点
print("100 + 200 =",100 + 200)
100 + 200 = 300
2. 输入
(1) input()
//Python提供了一个input(),可以让用户输入字符串,并存放到一个变量里
>>>name = input()
sherry
>>> name
'sherry'
//我们把代码改成
name = input('please enter your name: ')
print('hello,', name)
//再次运行这个程序,你会发现,会首先打印出please enter your name:,这样,用户就可以根据提示,输入名字后,得到hello, xxx的输出。
//每次运行该程序,根据用户输入的不同,输出结果也会不同
小结:
输入是Input,输出是Output,因此,我们把输入输出统称为Input/Output,或者简写为IO
input()和print()是在命令行下面最基本的输入和输出
网友评论