Input Techniques

1. Taking input using input() function -> this function by default takes string as input. 

Example:

Python3




#For string
str = input()
 
# For integers
n = int(input())
 
# For floating or decimal numbers
n = float(input())


2. Taking Multiple Inputs: Multiple inputs in Python can be taken with the help of the map() and split() methods. The split() method splits the space-separated inputs and returns an iterable whereas when this function is used with the map() function it can convert the inputs to float and int accordingly.

Example:

Python3




# For Strings
x, y = input().split()
 
# For integers and floating point
# numbers
m, n = map(int, input().split())
m, n = map(float, input().split())


3. Taking input as a list or tuple: For this, the split() and map() functions can be used. As these functions return an iterable we can convert the given iterable to the list, tuple, or set accordingly.

Example:

Python3




# For Input - 4 5 6 1 56 21
# (Space separated inputs)
n = list(map(int, input().split()))
print(n)


Output:

[4, 5, 6, 1, 56, 21]

4. Taking Fixed and variable numbers of input: 

Python3




# Input: w3wiki 2 0 2 0
str, *lst = input().split()
lst = list(map(int, lst))
 
print(str, lst)


Output:

w3wiki [2, 0, 2, 0]

Different Input and Output Techniques in Python3

An article describing basic Input and output techniques that we use while coding in python.

Similar Reads

Input Techniques

1. Taking input using input() function -> this function by default takes string as input....

Output Techniques

...