liveBook · Manning

Input()

As explained in Get Programming: Learn to code with Python

The input function is a Python built-in function that displays an optional prompt, waits for user text, and returns the entered text as a string.

input() is a Python built-in function for interacting with a user. It displays an optional prompt, waits until the user presses Enter, and returns everything entered as a string. Leave a space at the end of the prompt so the user's response is easy to read. section 11.2

Store a response

user_place = input("Where do you live? ") text = user_place.capitalize() + "!" print(text) The first line saves the response in user_place. The next line changes its capitalization and adds punctuation; print() displays the result. section 11.2

Every response from input() is text, even when the user types a number. Convert it before performing numerical operations: int() creates an integer and float() creates a decimal number. section 11.3

Calculate with responses

num1 = float(input("Enter a number: ")) num2 = float(input("Enter another number: ")) print(num1, "*", num2, "=", num1 * num2) Each input is converted to a float before multiplication. section 11.2

Remember these points when using input():

  • The program pauses at input() until the user presses Enter. section 11.3
  • Assign the result to a variable when later code needs the response. section 11.2
  • Convert numeric responses explicitly before calculations. section 11.3
Listing 11.4. Storing the user input
user_place = input("Where do you live? ")          #1
text = user_place.capitalize() + "!"               #2
print(text)                                        #3
print("I hear it's nice there!")                   #3

See a complete interaction that stores a response, modifies it, and prints messages. section 11.2

How Get Programming: Learn to code with Python covers it

How deep it goes
Explains prompts, waiting, assignment, and numeric conversion through short examples, without extending beyond basic input handling.
Examples
Uses prompts for names, secrets, colors, cities, numbers, and multiple-number multiplication.
What it assumes
Assumes basic Python statements and variables while teaching prompts, user responses, strings, and explicit numeric conversion.
What you can do after
Build interactive programs that collect responses, store them, transform text, convert numbers, and calculate results.
How it connects
Connects user input with variables, strings, print(), integer conversion, floating-point conversion, and arithmetic.

Also explained in

Compare how 7 books explain input() →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Get Programming: Learn to code with Python. The section links point to the parts of the book it draws on.