liveBook · Manning

Input()

As explained in Practices of the Python Pro

The input function is a Python built-in function that reads a line of text from standard input and returns it as a string.

input() reads a user's response from standard input, making a command-line program interactive. Use it when the program must pause, ask a question, and continue with the entered text. section 6.3.3

A practical input flow can:

Validated menu input

choice = input('Choose an option: ') while not option_choice_is_valid(choice, options): print('Invalid choice') choice = input('Choose an option: ') return options[choice.upper()] section 6.3.3

Listing 6.13. Getting a user’s choice of menu option
def option_choice_is_valid(choice, options):                #1
    return choice in options or choice.upper() in options


def get_option_choice(options):
    choice = input('Choose an option: ')                    #2
    while not option_choice_is_valid(choice, options):      #3
         print('Invalid choice')
        choice = input('Choose an option: ')
    return options[choice.upper()]                          #4

if __name__ == '__main__':
    ...

    chosen_option = get_option_choice(options)
    chosen_option.choose()

Shows input() used with validation, case normalization, and menu selection. section 6.3.3

How Practices of the Python Pro covers it

How deep it goes
Demonstrates prompts, validation loops, case handling, and reusable field collection without examining input internals.
Examples
Uses menu choices, bookmark titles, URLs, notes, and deletion IDs as interactive input.
What it assumes
Assumes basic Python functions and dictionaries while teaching prompting and repeated validation through short application steps.
What you can do after
Build it from scratch to create validated command-line prompts and collect required or optional values.
How it connects
Connects input() with presentation layers, while loops, validation, menu options, and command objects.

Also explained in

Compare how 7 books explain input() →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Practices of the Python Pro. The section links point to the parts of the book it draws on.