How To Take Input In Python?

Use `input()` to read a line of text from the user

Store the result in a variable: `name = input()`

Show a prompt message: `name = input(“Enter your name: “)`

Convert input to an integer: `age = int(input(“Enter age: “))`

Convert input to a float: `price = float(input(“Enter price: “))`

Read multiple values in one line: `a, b = input().split()`

Convert multiple values to integers: `a, b = map(int, input().split())`

Read a list of integers: `nums = list(map(int, input().split()))`

Read characters one by one from a string input: `s = input()`

Read multiple lines using a loop: `for _ in range(n): line = input()`

Read all remaining input at once: `import sys; data = sys.stdin.read()`

Read one line from standard input: `import sys; line = sys.stdin.readline()`

Read all lines into a list: `import sys; lines = sys.stdin.readlines()`

Suggested for You

Trending Today