SlideShare a Scribd company logo
Python-02| Input, Output & Import
 Python 2.7 offers two functions
a) raw_input()
b) input()
 Python 3.x (latest release) the raw_input() has been
renamed as input() and the old input() function (of
release 2.x) has been removed.
The raw_input() is used as:
variable = raw_input(<statement>)
For example:
name = raw_input(‘What is your name’)
The data you type will be save to variable ‘name’
The raw_input() always returns a string type. In above example the python
interpreter returns the value of age(i.e., 18) in string type.
See the next slide to clear this concept.
 Python through an error, as Python cannot add integer to a
string.
 It received 12 through raw_input() as a string.
 We required to use typecasting functions with
raw_input()/input() [of python 3.x]
•Python offers two function int() and float() to convert the value in
integer and float type.
•bool() can also be used to get data in true/false
Python will through an error if you entered string type using raw_input() inside
int() or float()
 This input() function works only in Python 2.x.
 It does not supported by Python 3.x although Python uses
input() but actually it is raw_input() renamed as input().
 The input() returns value accordingly i.e., whatever type we
provide the same will be considered.
 It doesn’t require type casting.
On some installation it doesn’t work properly and raise error thus it should be
avoided and raw_input() should be used.
In Python 3.x, this input() has been removed and uses
raw_input() which has been renamed as input().
Input() function in Python 3.x should require typecasting
as it also generate data in string type by default.
To take input from user we took two input function and two lines. What
if we want this process in one single line? See next slide for answer
This is multiple input in one line. What if I want to use only one input()
function to take multiple inputs?
 For this we use split() function
a, b = input(“Enter first and last name”).split()
Note in Python code,
both a and b would be
of string.
We can convert them
to int using
a, b = [int(a), int(b)]
We can also use list
comprehension, will discuss in
next slide
a, b = [int(x) for x in input(“Enter two number:”).split()]
 split() is a function/method used to split the input() function
into multiple values.
 The method split() returns a list of all the words in the string.
 split() is opposite of concatenation which combines strings
into one.
List of multiple values
Note in the output window, user enter 3 values separated by spaces.
By default i.e., if no separator is defined in split() , space will be used
by default.
Input(“Enter two number”)
10 20
This will considered as one string but split() divide this string
into two with respect to space between them
10 | 20
Separated by
comma
Python will through error if not
separated by comma
Separation can be done using any of the other argument
split(“:”), split(“s”), split(“5”), split(“#”)
Python-02| Input, Output & Import
Python uses print() function to produce output.
print “Hello”
print 5
print ‘hello’
print (“Hello world”)
print (5)
print (“sum of 2 & 3 is”, 2+3)
Example of Python 2.x
Example of Python 3.x
print() :- without argument print() function prints a
blank line.
Line separator
print(string) :- enclosed within quotes.
Allowed escape character
What is the difference between
print(“Hello”+ “World”) and
print(“Hello” , “World”)
No Space
with Space
First argument Second argument
print() function insert spaces between items automatically.
 If we don’t want a space as separator between
arguments then we can use sep attribute
Space is added automatically
between the arguments. This is by
default, we can change it and will
show you on next slide.
By default sep = ‘ ’
 It appends a newline automatically
 In Python 2.x, it appends a newline unless the
statement ends in a comma.
a, b = 10, 20 a, b = 10, 20
print “a=”, a print “a=”, a,
print “b=”, b print “b=”, b
a = 10 a = 10 b = 20
b = 20
Notice first print
statement ends
with a comma
output
End with space not new line
As we have seen that print() automatically appends a
new line and a space between different object, this is by
default
The actual syntax of the print() function is
print(*objects, sep=‘ ’, end = ‘n’, file=sys.stdout, flush=false)
 %i ➔ int type
 %d ➔ int type
 %f ➔ float type
 %s ➔ str type
 Syntax
Print(“formatted string” %(variable list))
 {} ➔ replacement operator
 It is used to format our output to make it look
attractive.
 This can be done by using the str.format() method.
 {} specify the order in which it is printed.
No need of
ordering
0 for Love and 1 for movie
 The backslash (  ) character is used to escape
characters
What if want to print n......use double
backslash 
Printing single quote ( ‘ )
Printing double quote ( “ )
Printing backslash using double backslash
Python-02| Input, Output & Import
 When our program grows bigger, it is a good idea to break
it into different modules.
 Module is a group of functions, variables, classes etc.
 A library is a collection of modules.
 Python module have a filename and end with the
extension .py
 Definitions inside a module can be imported to another
module or the interactive interpreter in Python. We use
the import keyword to do this.
Python-02| Input, Output & Import

More Related Content

What's hot (20)

PPTX
Variables in python
Jaya Kumari
 
PPTX
File in C language
Manash Kumar Mondal
 
PPT
Pointers C programming
Appili Vamsi Krishna
 
PPTX
python conditional statement.pptx
Dolchandra
 
PDF
Python exception handling
Mohammed Sikander
 
PPSX
Stack
Seema Sharma
 
PPTX
Chapter 17 Tuples
Praveen M Jigajinni
 
PPTX
Functions in python
colorsof
 
PDF
Python file handling
Prof. Dr. K. Adisesha
 
PPTX
Python Exception Handling
Megha V
 
PDF
Python strings
Mohammed Sikander
 
PDF
Datatypes in python
eShikshak
 
PPTX
Function in C program
Nurul Zakiah Zamri Tan
 
PPTX
Beginning Python Programming
St. Petersburg College
 
PPTX
File handling in Python
Megha V
 
PPTX
Functions in c++
Rokonuzzaman Rony
 
PDF
Arrays in python
moazamali28
 
PPTX
Looping Statements and Control Statements in Python
PriyankaC44
 
Variables in python
Jaya Kumari
 
File in C language
Manash Kumar Mondal
 
Pointers C programming
Appili Vamsi Krishna
 
python conditional statement.pptx
Dolchandra
 
Python exception handling
Mohammed Sikander
 
Chapter 17 Tuples
Praveen M Jigajinni
 
Functions in python
colorsof
 
Python file handling
Prof. Dr. K. Adisesha
 
Python Exception Handling
Megha V
 
Python strings
Mohammed Sikander
 
Datatypes in python
eShikshak
 
Function in C program
Nurul Zakiah Zamri Tan
 
Beginning Python Programming
St. Petersburg College
 
File handling in Python
Megha V
 
Functions in c++
Rokonuzzaman Rony
 
Arrays in python
moazamali28
 
Looping Statements and Control Statements in Python
PriyankaC44
 

Similar to Python-02| Input, Output & Import (20)

PPTX
Unit2 input output
deepak kumbhar
 
PPTX
Input statement- output statement concept.pptx
SindhuVelmukull
 
PDF
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
KosmikTech1
 
PPTX
The Input Statement in Core Python .pptx
Kavitha713564
 
PPTX
PROGRAMMING FOR PROBLEM SOLVING FOR STRING CONCEPT
factsandknowledge94
 
PPTX
20BCT23 – PYTHON PROGRAMMING.pptx
gokilabrindha
 
PPTX
Python basics
Hoang Nguyen
 
PPTX
Python basics
Luis Goldster
 
PPTX
Python basics
Tony Nguyen
 
PPTX
Python basics
Fraboni Ec
 
PPTX
Python basics
Harry Potter
 
PPTX
Python basics
Young Alista
 
PPTX
Python basics
James Wong
 
PPTX
Introduction on basic python and it's application
sriram2110
 
PPT
Python Programming Introduction demo.ppt
JohariNawab
 
PPTX
Python_Modullllllle_2-_AFV._Funda-1.pptx
tissot723
 
PDF
Lecture 0 - CS50's Introduction to Programming with Python.pdf
SrinivasPonugupaty1
 
PPTX
#Code2Create: Python Basics
GDGKuwaitGoogleDevel
 
PPTX
Python basics
RANAALIMAJEEDRAJPUT
 
PDF
Python lecture 03
Tanwir Zaman
 
Unit2 input output
deepak kumbhar
 
Input statement- output statement concept.pptx
SindhuVelmukull
 
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
KosmikTech1
 
The Input Statement in Core Python .pptx
Kavitha713564
 
PROGRAMMING FOR PROBLEM SOLVING FOR STRING CONCEPT
factsandknowledge94
 
20BCT23 – PYTHON PROGRAMMING.pptx
gokilabrindha
 
Python basics
Hoang Nguyen
 
Python basics
Luis Goldster
 
Python basics
Tony Nguyen
 
Python basics
Fraboni Ec
 
Python basics
Harry Potter
 
Python basics
Young Alista
 
Python basics
James Wong
 
Introduction on basic python and it's application
sriram2110
 
Python Programming Introduction demo.ppt
JohariNawab
 
Python_Modullllllle_2-_AFV._Funda-1.pptx
tissot723
 
Lecture 0 - CS50's Introduction to Programming with Python.pdf
SrinivasPonugupaty1
 
#Code2Create: Python Basics
GDGKuwaitGoogleDevel
 
Python basics
RANAALIMAJEEDRAJPUT
 
Python lecture 03
Tanwir Zaman
 
Ad

More from Mohd Sajjad (6)

PPTX
Python-04| Fundamental data types vs immutability
Mohd Sajjad
 
PDF
Python-03| Data types
Mohd Sajjad
 
PDF
Python-01| Fundamentals
Mohd Sajjad
 
PPTX
Python-00 | Introduction and installing
Mohd Sajjad
 
PPTX
Secure your folder with password/without any software
Mohd Sajjad
 
PPTX
SNMP Protocol
Mohd Sajjad
 
Python-04| Fundamental data types vs immutability
Mohd Sajjad
 
Python-03| Data types
Mohd Sajjad
 
Python-01| Fundamentals
Mohd Sajjad
 
Python-00 | Introduction and installing
Mohd Sajjad
 
Secure your folder with password/without any software
Mohd Sajjad
 
SNMP Protocol
Mohd Sajjad
 
Ad

Recently uploaded (20)

PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PPTX
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
Dimensions of Societal Planning in Commonism
StefanMz
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 

Python-02| Input, Output & Import

  • 2.  Python 2.7 offers two functions a) raw_input() b) input()  Python 3.x (latest release) the raw_input() has been renamed as input() and the old input() function (of release 2.x) has been removed.
  • 3. The raw_input() is used as: variable = raw_input(<statement>) For example: name = raw_input(‘What is your name’) The data you type will be save to variable ‘name’ The raw_input() always returns a string type. In above example the python interpreter returns the value of age(i.e., 18) in string type. See the next slide to clear this concept.
  • 4.  Python through an error, as Python cannot add integer to a string.  It received 12 through raw_input() as a string.  We required to use typecasting functions with raw_input()/input() [of python 3.x]
  • 5. •Python offers two function int() and float() to convert the value in integer and float type. •bool() can also be used to get data in true/false
  • 6. Python will through an error if you entered string type using raw_input() inside int() or float()
  • 7.  This input() function works only in Python 2.x.  It does not supported by Python 3.x although Python uses input() but actually it is raw_input() renamed as input().  The input() returns value accordingly i.e., whatever type we provide the same will be considered.  It doesn’t require type casting. On some installation it doesn’t work properly and raise error thus it should be avoided and raw_input() should be used.
  • 8. In Python 3.x, this input() has been removed and uses raw_input() which has been renamed as input(). Input() function in Python 3.x should require typecasting as it also generate data in string type by default.
  • 9. To take input from user we took two input function and two lines. What if we want this process in one single line? See next slide for answer This is multiple input in one line. What if I want to use only one input() function to take multiple inputs?
  • 10.  For this we use split() function a, b = input(“Enter first and last name”).split() Note in Python code, both a and b would be of string. We can convert them to int using a, b = [int(a), int(b)] We can also use list comprehension, will discuss in next slide
  • 11. a, b = [int(x) for x in input(“Enter two number:”).split()]  split() is a function/method used to split the input() function into multiple values.  The method split() returns a list of all the words in the string.  split() is opposite of concatenation which combines strings into one. List of multiple values
  • 12. Note in the output window, user enter 3 values separated by spaces. By default i.e., if no separator is defined in split() , space will be used by default.
  • 13. Input(“Enter two number”) 10 20 This will considered as one string but split() divide this string into two with respect to space between them 10 | 20
  • 14. Separated by comma Python will through error if not separated by comma Separation can be done using any of the other argument split(“:”), split(“s”), split(“5”), split(“#”)
  • 16. Python uses print() function to produce output. print “Hello” print 5 print ‘hello’ print (“Hello world”) print (5) print (“sum of 2 & 3 is”, 2+3) Example of Python 2.x Example of Python 3.x
  • 17. print() :- without argument print() function prints a blank line. Line separator
  • 18. print(string) :- enclosed within quotes. Allowed escape character
  • 19. What is the difference between print(“Hello”+ “World”) and print(“Hello” , “World”) No Space with Space First argument Second argument print() function insert spaces between items automatically.
  • 20.  If we don’t want a space as separator between arguments then we can use sep attribute Space is added automatically between the arguments. This is by default, we can change it and will show you on next slide. By default sep = ‘ ’
  • 21.  It appends a newline automatically  In Python 2.x, it appends a newline unless the statement ends in a comma. a, b = 10, 20 a, b = 10, 20 print “a=”, a print “a=”, a, print “b=”, b print “b=”, b a = 10 a = 10 b = 20 b = 20 Notice first print statement ends with a comma output
  • 22. End with space not new line
  • 23. As we have seen that print() automatically appends a new line and a space between different object, this is by default The actual syntax of the print() function is print(*objects, sep=‘ ’, end = ‘n’, file=sys.stdout, flush=false)
  • 24.  %i ➔ int type  %d ➔ int type  %f ➔ float type  %s ➔ str type  Syntax Print(“formatted string” %(variable list))
  • 25.  {} ➔ replacement operator  It is used to format our output to make it look attractive.  This can be done by using the str.format() method.  {} specify the order in which it is printed.
  • 26. No need of ordering 0 for Love and 1 for movie
  • 27.  The backslash ( ) character is used to escape characters What if want to print n......use double backslash Printing single quote ( ‘ ) Printing double quote ( “ ) Printing backslash using double backslash
  • 29.  When our program grows bigger, it is a good idea to break it into different modules.  Module is a group of functions, variables, classes etc.  A library is a collection of modules.  Python module have a filename and end with the extension .py  Definitions inside a module can be imported to another module or the interactive interpreter in Python. We use the import keyword to do this.