liveBook · Manning

Input()

As explained in Learn AI-Assisted Python Programming, Second Edition

The Python input function reads a line of text from an input stream, typically the user's keyboard, and returns it as a string.

input() is a built-in Python function for getting text from the user. It displays a prompt, reads a line typed at the keyboard, and returns that line as a string. section 4.3.1

Use input() as the input step in a larger program:

  • Pass a prompt such as "What is your name? ". section 4.3.1
  • Store the returned text in a variable. section 4.3.1
  • Convert the string when later processing needs a number, using int(input(...)). section 4.4

Reading an age

age = int(input("Enter your age: ")) asks for text, converts it to an integer, and stores it in age. Conditional statements can then use that value to choose a message. section 4.4

>>> name = input("What is your name? ")
What is your name? Dan
>>> name
'Dan'

See the interactive name example: input() receives typed text, and print() displays a greeting using the stored value. section 4.3.1

How Learn AI-Assisted Python Programming, Second Edition covers it

How deep it goes
Explains prompts, string returns, numeric conversion, and placement in input-process-output design, but not input-stream internals.
Examples
Demonstrates name collection, age classification, and user-provided words for spelling suggestions.
What it assumes
Assumes basic function calls and variables while teaching prompts, returned strings, and conversion for numeric processing.
What you can do after
Apply it via Python to collect keyboard text and feed that value into later processing.
How it connects
Connects input() with functions, strings, integer conversion, print(), conditional statements, and input-process-output design.

Also explained in

Compare how 7 books explain input() →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn AI-Assisted Python Programming, Second Edition. The section links point to the parts of the book it draws on.