Python provides 2 built in functions to read a line of text from standard input
1] raw_input()
2] input()
1] raw_input() :
it is used to read data from the user or from the keyboard.
it is only supports to the python 2.x versions.
syntax:
raw_input("message")
example:
we are executing this statement in latest version of python.
>>> x=raw_input("enter a number")
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
x=raw_input("enter a number")
NameError: name 'raw_input' is not defined
>>>
raw_input() function is deleted from latest versions of python.
2] input() :
it is used to read data from the user or from the keyboard.
it is supported to the python 3.x versions onwards.
syntax:
input("message")
example:
>>> x=input("enter a number:")
enter a number:45
>>> x
'45'
>>>
1] raw_input()
2] input()
1] raw_input() :
it is used to read data from the user or from the keyboard.
it is only supports to the python 2.x versions.
syntax:
raw_input("message")
example:
we are executing this statement in latest version of python.
>>> x=raw_input("enter a number")
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
x=raw_input("enter a number")
NameError: name 'raw_input' is not defined
>>>
raw_input() function is deleted from latest versions of python.
2] input() :
it is used to read data from the user or from the keyboard.
it is supported to the python 3.x versions onwards.
syntax:
input("message")
example:
>>> x=input("enter a number:")
enter a number:45
>>> x
'45'
>>>
No comments:
Post a Comment