三十九、input方法
1、定义:
input(...)
input([prompt]) -> value
Equivalent to eval(raw_input(prompt)).2、解释:等价于:eval(raw_input(prompt)),因此,下一个介绍raw_input
3、举例:
>>> aa = input('请输入内容或python表达式:')
请输入内容或python表达式:range(5)
>>> aa
[0, 1, 2, 3, 4]
>>> aa = input('请输入内容或python表达式:')
请输入内容或python表达式:abc
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
NameError: name 'abc' is not defined
>>> aa = input('请输入内容或python表达式:')
请输入内容或python表达式:'anc'
>>> aa
'anc'四十、raw_input方法
1、定义:
raw_input(...)
raw_input([prompt]) -> string
Read a string from standard input. The trailing newline is stripped.
If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.
On Unix, GNU readline is used if enabled. The prompt string, if given,
is printed without a trailing newline before reading.2、解释:将标准输入的内容转换成字符串, 此方法的输入参数为提示字符串,不计入标准输入内容中。
3、举例:
>>> aa = raw_input('请输入内容或python表达式:')
请输入内容或python表达式:1=3
>>> aa
'1=3'
>>> aa = raw_input('请输入内容或python表达式:')
请输入内容或python表达式:abc
>>> aa
'abc'
>>> aa = raw_input('请输入内容或python表达式:')
请输入内容或python表达式:range(4)
>>> aa
'range(4)'
Copyright © 2021.aoyanming个人博客站
发表评论