为了检查目的,您可以使用input()方法,然后相应地进行决定。
[iahmad@ijaz001 ~]$ python2.7
Python 2.7.15 (default, May 9 2018, 11:32:33)
[GCC 7.3.1 20180130 (Red Hat 7.3.1-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> x=input()
'hi'
>>> type(x)
<type 'str'>
>>> x=input()
10
>>>
>>> type(x)
<type 'int'>
>>>
[iahmad@ijaz001 ~]$ python3.6
Python 3.6.5 (default, Apr 4 2018, 15:09:05)
[GCC 7.3.1 20180130 (Red Hat 7.3.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> x=eval(input())
'hi'
>>>
>>> type(x)
<class 'str'>
>>>
>>> x=eval(input())
10
>>>
>>> type(x)
<class 'int'>