Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use raw_input in Python 3

import sys print(sys.platform) print(2**100) raw_input() 

I am using Python 3.1 and can't get the raw_input to "freeze" the dos pop-up. The book I'm reading is for Python 2.5 and I'm using Python 3.1

What should I do to fix this?

like image 303
Lonnie Price Avatar asked Jun 05 '09 08:06

Lonnie Price


People also ask

Can we use raw_input in Python 3?

The input function is used only in Python 2.The raw_input() function is similar to input() function in Python 3. x. Developers are recommended to use raw_input function in Python 2.

What is the difference between input () and raw_input () in Python?

There are two functions that can be used to read data or input from the user in python: raw_input() and input(). The results can be stored into a variable. raw_input() – It reads the input or command and returns a string. input() – Reads the input and returns a python type like list, tuple, int, etc.

Why is raw_input not defined in Python?

The NameError: name 'raw_input' is not defined occurs when you try to call the raw_input() function using Python major version 3. You can only use raw_input() in Python 2. To solve this error, replace all instances of raw_input() with the input() function in your program.


2 Answers

Starting with Python 3, raw_input() was renamed to input().

From What’s New In Python 3.0, Builtins section second item.

like image 137
balpha Avatar answered Sep 25 '22 13:09

balpha


This works in Python 3.x and 2.x:

# Fix Python 2.x. try: input = raw_input except NameError: pass print("Hi " + input("Say something: ")) 
like image 32
Cees Timmerman Avatar answered Sep 22 '22 13:09

Cees Timmerman