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
Ad

More Related Content

What's hot (20)

Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
TMARAGATHAM
 
Python-Inheritance.pptx
Python-Inheritance.pptxPython-Inheritance.pptx
Python-Inheritance.pptx
Karudaiyar Ganapathy
 
Python list
Python listPython list
Python list
Mohammed Sikander
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
Pavith Gunasekara
 
Python array
Python arrayPython array
Python array
Arnab Chakraborty
 
Strings in python
Strings in pythonStrings in python
Strings in python
Prabhakaran V M
 
Python : Data Types
Python : Data TypesPython : Data Types
Python : Data Types
Emertxe Information Technologies Pvt Ltd
 
Chapter 07 inheritance
Chapter 07 inheritanceChapter 07 inheritance
Chapter 07 inheritance
Praveen M Jigajinni
 
Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
Mohammed Sikander
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
Mohammed Sikander
 
8 python data structure-1
8 python data structure-18 python data structure-1
8 python data structure-1
Prof. Dr. K. Adisesha
 
Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptx
AkshayAggarwal79
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
Emertxe Information Technologies Pvt Ltd
 
Values and Data types in python
Values and Data types in pythonValues and Data types in python
Values and Data types in python
Jothi Thilaga P
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
Devashish Kumar
 
Functions in python
Functions in pythonFunctions in python
Functions in python
colorsof
 
Introduction to Python
Introduction to Python  Introduction to Python
Introduction to Python
Mohammed Sikander
 
Modules in Python Programming
Modules in Python ProgrammingModules in Python Programming
Modules in Python Programming
sambitmandal
 
Polymorphism in Python
Polymorphism in Python Polymorphism in Python
Polymorphism in Python
Home
 
NUMPY
NUMPY NUMPY
NUMPY
SharmilaChidaravalli
 

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

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

More from Mohd Sajjad (6)

Python-04| Fundamental data types vs immutability
Python-04| Fundamental data types vs immutabilityPython-04| Fundamental data types vs immutability
Python-04| Fundamental data types vs immutability
Mohd Sajjad
 
Python-03| Data types
Python-03| Data typesPython-03| Data types
Python-03| Data types
Mohd Sajjad
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
Mohd Sajjad
 
Python-00 | Introduction and installing
Python-00 | Introduction and installingPython-00 | Introduction and installing
Python-00 | Introduction and installing
Mohd Sajjad
 
Secure your folder with password/without any software
Secure your folder with password/without any softwareSecure your folder with password/without any software
Secure your folder with password/without any software
Mohd Sajjad
 
SNMP Protocol
SNMP ProtocolSNMP Protocol
SNMP Protocol
Mohd Sajjad
 
Python-04| Fundamental data types vs immutability
Python-04| Fundamental data types vs immutabilityPython-04| Fundamental data types vs immutability
Python-04| Fundamental data types vs immutability
Mohd Sajjad
 
Python-03| Data types
Python-03| Data typesPython-03| Data types
Python-03| Data types
Mohd Sajjad
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
Mohd Sajjad
 
Python-00 | Introduction and installing
Python-00 | Introduction and installingPython-00 | Introduction and installing
Python-00 | Introduction and installing
Mohd Sajjad
 
Secure your folder with password/without any software
Secure your folder with password/without any softwareSecure your folder with password/without any software
Secure your folder with password/without any software
Mohd Sajjad
 
Ad

Recently uploaded (20)

pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
Engage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdfEngage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdf
TechSoup
 
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx   quiz by Ridip HazarikaTHE STG QUIZ GROUP D.pptx   quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
Ridip Hazarika
 
Real GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for SuccessReal GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for Success
Mark Soia
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Link your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRMLink your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRM
Celine George
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Sugar-Sensing Mechanism in plants....pptx
Sugar-Sensing Mechanism in plants....pptxSugar-Sensing Mechanism in plants....pptx
Sugar-Sensing Mechanism in plants....pptx
Dr. Renu Jangid
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
Herbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptxHerbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptx
RAJU THENGE
 
Introduction-to-Communication-and-Media-Studies-1736283331.pdf
Introduction-to-Communication-and-Media-Studies-1736283331.pdfIntroduction-to-Communication-and-Media-Studies-1736283331.pdf
Introduction-to-Communication-and-Media-Studies-1736283331.pdf
james5028
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Engage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdfEngage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdf
TechSoup
 
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx   quiz by Ridip HazarikaTHE STG QUIZ GROUP D.pptx   quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
Ridip Hazarika
 
Real GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for SuccessReal GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for Success
Mark Soia
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Link your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRMLink your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRM
Celine George
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Sugar-Sensing Mechanism in plants....pptx
Sugar-Sensing Mechanism in plants....pptxSugar-Sensing Mechanism in plants....pptx
Sugar-Sensing Mechanism in plants....pptx
Dr. Renu Jangid
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
Herbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptxHerbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptx
RAJU THENGE
 
Introduction-to-Communication-and-Media-Studies-1736283331.pdf
Introduction-to-Communication-and-Media-Studies-1736283331.pdfIntroduction-to-Communication-and-Media-Studies-1736283331.pdf
Introduction-to-Communication-and-Media-Studies-1736283331.pdf
james5028
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 

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.