输入和输出基本命令

输出(print)

用print()在括号中加上字符串,就可以向屏幕上输出指定的文字

print('hello, world')

可以接受多个字符串,用逗号“,”隔开,就可以连成一串输出:

>>> print('The quick brown fox', 'jumps over', 'the lazy dog')
The quick brown fox jumps over the lazy dog

print()会依次打印每个字符串,遇到逗号“,”会输出一个空格,因此,输出的字符串是这样拼起来的:

python 执行过程打印 python打印命令_python

print()也可以打印整数,或者计算结果:

>>> print(100 + 200)
300
>>> print('100 + 200 =', 100 + 200)
100 + 200 = 300

输入(input)

Python提供了一个input(),可以让用户输入字符串,并存放到一个变量里。

>>> name = input()

答案是存放到name变量里,但是此时输入进去的格式字符串格式,若需要进行运算则是需要进行转换格式。

print可直接打印字符串格式的数据变量。

name = input('please enter your name: ')
print('hello,', name)

小结

输入是Input,输出是Output,因此,我们把输入输出统称为Input/Output,或者简写为IO