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)

PDF
Arrays in python
moazamali28
 
PDF
Introduction to Python
Mohammed Sikander
 
PPTX
Tuple in python
Sharath Ankrajegowda
 
PPTX
Python variables and data types.pptx
AkshayAggarwal79
 
PPTX
String Manipulation in Python
Pooja B S
 
PPTX
single linked list
Sathasivam Rangasamy
 
PPTX
Functions in C
Kamal Acharya
 
PPTX
Data Structures in Python
Devashish Kumar
 
PDF
Datatypes in python
eShikshak
 
PPTX
File handling in Python
Megha V
 
PPTX
Stack and Queue
Apurbo Datta
 
PDF
Python programming : Control statements
Emertxe Information Technologies Pvt Ltd
 
PPTX
Operators in python
deepalishinkar1
 
PDF
Python tuple
Mohammed Sikander
 
PPTX
Arrays in c
Jeeva Nanthini
 
PDF
Python final ppt
Ripal Ranpara
 
PPT
Queue data structure
anooppjoseph
 
PPTX
Control Statements in Java
Niloy Saha
 
PDF
Python-03| Data types
Mohd Sajjad
 
Arrays in python
moazamali28
 
Introduction to Python
Mohammed Sikander
 
Tuple in python
Sharath Ankrajegowda
 
Python variables and data types.pptx
AkshayAggarwal79
 
String Manipulation in Python
Pooja B S
 
single linked list
Sathasivam Rangasamy
 
Functions in C
Kamal Acharya
 
Data Structures in Python
Devashish Kumar
 
Datatypes in python
eShikshak
 
File handling in Python
Megha V
 
Stack and Queue
Apurbo Datta
 
Python programming : Control statements
Emertxe Information Technologies Pvt Ltd
 
Operators in python
deepalishinkar1
 
Python tuple
Mohammed Sikander
 
Arrays in c
Jeeva Nanthini
 
Python final ppt
Ripal Ranpara
 
Queue data structure
anooppjoseph
 
Control Statements in Java
Niloy Saha
 
Python-03| Data types
Mohd Sajjad
 

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

PPTX
The Input Statement in Core Python .pptx
Kavitha713564
 
PPTX
Input statement- output statement concept.pptx
SindhuVelmukull
 
PDF
Basic Concepts in Python
Sumit Satam
 
PPTX
Unit2 input output
deepak kumbhar
 
PPTX
Introduction on basic python and it's application
sriram2110
 
PPTX
funadamentals of python programming language (right from scratch)
MdFurquan7
 
PPTX
INTRODUCTION TO FUNCTIONS IN PYTHON
vikram mahendra
 
PPTX
Python variables in the computer science.pptx
Rajasekhar364622
 
PPTX
Python 3.pptx
HarishParthasarathy4
 
PPT
Os Vanrossum
oscon2007
 
PPT
Python Programming Introduction demo.ppt
JohariNawab
 
PPT
Python Built-in Functions by A Technologies
AmitavaBiswas17
 
PDF
The Ring programming language version 1.8 book - Part 94 of 202
Mahmoud Samir Fayed
 
PPTX
MODULE. .pptx
Alpha337901
 
PPTX
FSTREAM,ASSERT LIBRARY & CTYPE LIBRARY.
Meghaj Mallick
 
PPT
Python 3000
Alexandro Colorado
 
PDF
advanced python for those who have beginner level experience with python
barmansneha1204
 
PDF
Advanced Python after beginner python for intermediate learners
barmansneha1204
 
PPTX
Lecture 15_Strings and Dynamic Memory Allocation.pptx
JawadTanvir
 
PPTX
GRADE 11 Chapter 5 - Python Fundamentals.pptx
DeepaRavi21
 
The Input Statement in Core Python .pptx
Kavitha713564
 
Input statement- output statement concept.pptx
SindhuVelmukull
 
Basic Concepts in Python
Sumit Satam
 
Unit2 input output
deepak kumbhar
 
Introduction on basic python and it's application
sriram2110
 
funadamentals of python programming language (right from scratch)
MdFurquan7
 
INTRODUCTION TO FUNCTIONS IN PYTHON
vikram mahendra
 
Python variables in the computer science.pptx
Rajasekhar364622
 
Python 3.pptx
HarishParthasarathy4
 
Os Vanrossum
oscon2007
 
Python Programming Introduction demo.ppt
JohariNawab
 
Python Built-in Functions by A Technologies
AmitavaBiswas17
 
The Ring programming language version 1.8 book - Part 94 of 202
Mahmoud Samir Fayed
 
MODULE. .pptx
Alpha337901
 
FSTREAM,ASSERT LIBRARY & CTYPE LIBRARY.
Meghaj Mallick
 
Python 3000
Alexandro Colorado
 
advanced python for those who have beginner level experience with python
barmansneha1204
 
Advanced Python after beginner python for intermediate learners
barmansneha1204
 
Lecture 15_Strings and Dynamic Memory Allocation.pptx
JawadTanvir
 
GRADE 11 Chapter 5 - Python Fundamentals.pptx
DeepaRavi21
 
Ad

Recently uploaded (20)

PDF
I3PM Case study smart parking 2025 with uptoIP® and ABP
MIPLM
 
PPTX
How to Configure Taxes in Company Currency in Odoo 18 Accounting
Celine George
 
PPTX
MATH 8 QUARTER 1 WEEK 1 LESSON 2 PRESENTATION
JohnGuillerNestalBah1
 
PDF
AI-assisted IP-Design lecture from the MIPLM 2025
MIPLM
 
PPTX
How to Add a Custom Button in Odoo 18 POS Screen
Celine George
 
PDF
DIGESTION OF CARBOHYDRATES ,PROTEINS AND LIPIDS
raviralanaresh2
 
PDF
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.06.25.pdf
TechSoup
 
PPTX
How to Create & Manage Stages in Odoo 18 Helpdesk
Celine George
 
PPTX
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
PDF
I3PM Industry Case Study Siemens on Strategic and Value-Oriented IP Management
MIPLM
 
PPTX
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
PDF
Cooperative wireless communications 1st Edition Yan Zhang
jsphyftmkb123
 
PDF
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
PPTX
Parsing HTML read and write operations and OS Module.pptx
Ramakrishna Reddy Bijjam
 
PPTX
How to Configure Refusal of Applicants in Odoo 18 Recruitment
Celine George
 
PPTX
Life and Career Skills Lesson 2.pptxProtective and Risk Factors of Late Adole...
ryangabrielcatalon40
 
PPTX
Exploring Linear and Angular Quantities and Ergonomic Design.pptx
AngeliqueTolentinoDe
 
PDF
TLE 8 QUARTER 1 MODULE WEEK 1 MATATAG CURRICULUM
denniseraya1997
 
PDF
WATERSHED MANAGEMENT CASE STUDIES - ULUGURU MOUNTAINS AND ARVARI RIVERpdf
Ar.Asna
 
PPTX
PLANNING FOR EMERGENCY AND DISASTER MANAGEMENT ppt.pptx
PRADEEP ABOTHU
 
I3PM Case study smart parking 2025 with uptoIP® and ABP
MIPLM
 
How to Configure Taxes in Company Currency in Odoo 18 Accounting
Celine George
 
MATH 8 QUARTER 1 WEEK 1 LESSON 2 PRESENTATION
JohnGuillerNestalBah1
 
AI-assisted IP-Design lecture from the MIPLM 2025
MIPLM
 
How to Add a Custom Button in Odoo 18 POS Screen
Celine George
 
DIGESTION OF CARBOHYDRATES ,PROTEINS AND LIPIDS
raviralanaresh2
 
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.06.25.pdf
TechSoup
 
How to Create & Manage Stages in Odoo 18 Helpdesk
Celine George
 
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
I3PM Industry Case Study Siemens on Strategic and Value-Oriented IP Management
MIPLM
 
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
Cooperative wireless communications 1st Edition Yan Zhang
jsphyftmkb123
 
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
Parsing HTML read and write operations and OS Module.pptx
Ramakrishna Reddy Bijjam
 
How to Configure Refusal of Applicants in Odoo 18 Recruitment
Celine George
 
Life and Career Skills Lesson 2.pptxProtective and Risk Factors of Late Adole...
ryangabrielcatalon40
 
Exploring Linear and Angular Quantities and Ergonomic Design.pptx
AngeliqueTolentinoDe
 
TLE 8 QUARTER 1 MODULE WEEK 1 MATATAG CURRICULUM
denniseraya1997
 
WATERSHED MANAGEMENT CASE STUDIES - ULUGURU MOUNTAINS AND ARVARI RIVERpdf
Ar.Asna
 
PLANNING FOR EMERGENCY AND DISASTER MANAGEMENT ppt.pptx
PRADEEP ABOTHU
 
Ad

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.