Advertisements
Advertisements
प्रश्न
We will try to read input from the user. Press Ctrl-d and see what happens:
>>> s = raw_input('Enter something --> ')
कोड लेखन
Advertisements
उत्तर
In Python 2, pressing Ctrl-D sends an end-of-file signal. Since no input is supplied, raw_input() raises an EOFError exception. It can be handled as follows:
try:
s = input("Enter something --> ")
except EOFError:
print("End of input reached.")
In Windows, Ctrl-Z followed by Enter generally performs the equivalent EOF operation.
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
