In Python2.*, input([prompt]) was equivalent to eval(raw_input([prompt])).
In Python3.*, input([prompt]) of Python2.* was removed and raw_input([prompt]) was renamed as input([[rompt]).
* Python 2.6에서 input() 함수 테스트하기
명령행프롬프트> python
Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "icense" for more information.
>>> x = input("Input a number: ")
Input a number: aaa
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
NameError: name 'aaa' is not defined
* Python 3.1에서 input() 함수 테스트하기
명령행프롬프트> python
Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> x = input("Input a number: ")
Input a number: aaa
>>> print x
File "<stdin>", line 1
print x
^
SyntaxError: invalid syntax
>>> print(x)
aaa
>>> type(x)
<class 'str'>
In Python3.*, input([prompt]) of Python2.* was removed and raw_input([prompt]) was renamed as input([[rompt]).
* Python 2.6에서 input() 함수 테스트하기
명령행프롬프트> python
Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "icense" for more information.
>>> x = input("Input a number: ")
Input a number: aaa
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
NameError: name 'aaa' is not defined
* Python 3.1에서 input() 함수 테스트하기
명령행프롬프트> python
Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> x = input("Input a number: ")
Input a number: aaa
>>> print x
File "<stdin>", line 1
print x
^
SyntaxError: invalid syntax
>>> print(x)
aaa
>>> type(x)
<class 'str'>
'프로그래밍 > Python' 카테고리의 다른 글
조립제법(Horner의 방법) 예제 2 for Python (0) | 2010.04.12 |
---|---|
숫자 맞추기 게임 with Python (0) | 2009.11.05 |
스트링 리스트에서 스트링 찾기(find) with Python (0) | 2009.04.22 |
스트링 배열 정렬(sorting)하기 with Python (0) | 2009.04.15 |
Pollard's rho method 소개: 정수의 인수분해(factorizing integers) with Python (0) | 2009.03.23 |