Ask coding questions

← Back to all posts
How to add a input in python
AmalinaJamil

I don't know how to add an input in python because i'm a beginner.
please help

Voters
C-HH
jrjamir
AmalinaJamil
Comments
hotnewtop
Muffinlavania

Use @UniqueOstrich18 for the answer, but just use input() like he said
Put whatever variable you want before it, and in the paraenthesis, put what you want to ask in quotes, like this:
Your_Variable = input("Ask your Question Here")

Then you can call this variable later like @UniqueOstrich18 said,
You just either print it like this:

print(Your_Variable)

Or add text before it, and add a plus sign then your variable
Like this:
print("The Answer to my question was"+Your_Variable)

UniqueOstrich18

You can use the input() statement:

If this was helpful, please mark it as the answer.

multicoder2021

You can also do:

multicoder2021

Everyone's given the solution, mark at least one as the answer...

It's simple:

Or, if you want to use Python 2,

You can also add a 'str()' or 'int()' to specify what data type is allowed:

It will give an error if you type the wrong data type (integer or string)

multicoder2021

Exactly what both of them said, use the input() function.
You can also specify if it can be an integer or string
Example:

Also, a suggestion:
Instead of printing the variable directly, or doing it like this:
print("TEXT" , variable_name)
You can use the .format() method or use f-strings.
Example of the .format():

Example of f-strings [I prefer this method]: