0% found this document useful (0 votes)
3 views12 pages

Python Input Output Methods Guide

Notes python

Uploaded by

prajwal2.ece24
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views12 pages

Python Input Output Methods Guide

Notes python

Uploaded by

prajwal2.ece24
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

L-1: INPUT OUTPUT METHODS IN PYTHON

1. How to input a single String?

Str1=input()

Note: In online coding tests, do not type any statement inside input() function

2. How to input a single Integer?

n=int(input())

Note: By default, input() function takes string values. Use int() function to convert string into an
integer.

3. How to input a Single Float value?

n=float(input())

Note: By default, input() function takes string values. Use float() function to convert string into an float.

4. How to input multiple strings separated by space?

For Ex : Rohit Rahul Virat Hardik

str1=input() #As of now, str1 is a single string, NOT a list.

list1=[Link]() #After split(), we always get a list

#Now, list1[0]=’Rohit’ and so on…

5. How to input multiple strings separated by comma?

For Ex : Rohit,Rahul,Virat,Hardik

str1=input() #As of now, str1 is a single string, NOT a list.

list1=[Link](‘.’) #After split(), we always get a list

L-2:
6. How to input multiple strings one below the other?

For Ex :

Rohit

Rahul

Virat

Hardik

n=int(input()) #This is the no of elements

list1=[] #start with an empty list

for i in range(n):
[Link](input())

7. How to input Multiple Integers Separated by Space?

For Ex : 2 4 6 8

str1=input() #As of now, str1 is a single string. NOT a list

list1=[Link]() #After split, we always get a list

#But as of now, list1 is a list of strings, but


not integers

list1=[int(i) for i in list1] #Now, we get a list of integers

8. How to input Multiple Integers Separated by Comma?

For Ex : 2,4,6,8

str1=input() #As of now, str1 is a single string. NOT a list

list1=[Link](‘,’) #After split, we always get a list

#But as of now, list1 is a list of strings, but


not integers

list1=[int(i) for i in list1] #Now, we get a list of integers

9. How to input multiple integers one below the other?

For Ex :

n=int(input()) #This is the no of elements

list1=[] #Start with an empty list

for i in range(n):

[Link](int(input())

10. How to print elements of a list in a single line separated by space.

For Ex : 2 4 6 8

list1=[2,4,6,8]

print(*list1) #This will print elements of list1 in a single line separated by space

11. How to print elements of a list in a single line separated by comma.

For Ex : 2,4,6,8

list1=[2,4,6,8]

print(*list1,sep=’,’) #This will print elements of list1 in a single line separated by comma
12. How to print elements of a list one below the other.

For Ex :

list1=[2,4,6,8]

print(*list1,sep=’\n’) # This will print elements of list1 one below the other

Mock Test 1 : Input Output Methods


Mock Test -2 : Perfect Squares
Mock Test 3 : Leap Years
Mock Test 4 : Prime Numbers
Mock Test 5 : Number Based Programs

You might also like