Accepting Input

The input() function is used to accept user input from the console. This function prompts the user with a message and waits for input.

name = input(“Enter your name: “)

The input is returned as a string, so you may need to convert it to the desired data type. Here, we’re converting the string input to an integer.

age = int(input(“Enter age: “))

Get Python Made Easy now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.