用Python进行程序设计,输入是通过input( )函数来实现的, input( )的一般格式为:
x = input('提示:')
该函数返回输入的对象。可输入数字、字符串和其它任意类 型对象。
在Python 3.x中,input()函数用来接收用户的键盘输入, 不论用户输入数据时使用什么界定符,input()函数的返 回结果都是字符串,需要将其转换为相应的类型再处理。
>>> x = input('Please input:')
Please input:3
>>> print(type(x))
<class 'str'>
>>> x = input('Please input:')
Please input:'1'
>>> print(type(x))
<class 'str'>
>>> x = input('Please input:')
Please input:[1,2,3]
>>> print(type(x))
<class 'str'>
Python 3.x中使用print()函数进行输出。
>>> print(3, 5, 7)
3 5 7
>>> print(3, 5, 7, sep=',') #指定分隔符
3,5,7
>>> print(3, 5, 7, sep=':')
3:5:7
>>> for i in range(10,20):
print(i, end=' ') #不换行
10 11 12 13 14 15 16 17 18 19