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)

Packages In Python Tutorial
Packages In Python TutorialPackages In Python Tutorial
Packages In Python Tutorial
Simplilearn
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS Concept
Boopathi K
 
Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
Emertxe Information Technologies Pvt Ltd
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
Harsh Pathak
 
Constructor
ConstructorConstructor
Constructor
poonamchopra7975
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
Vineeta Garg
 
Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++
Janki Shah
 
Dictionaries in Python
Dictionaries in PythonDictionaries in Python
Dictionaries in Python
baabtra.com - No. 1 supplier of quality freshers
 
Type casting in c programming
Type casting in c programmingType casting in c programming
Type casting in c programming
Rumman Ansari
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
Abdullah Al-hazmy
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
eShikshak
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
Viji B
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
Harshita Yadav
 
Introduction to c++ ppt
Introduction to c++ pptIntroduction to c++ ppt
Introduction to c++ ppt
Prof. Dr. K. Adisesha
 
Inter Thread Communicationn.pptx
Inter Thread Communicationn.pptxInter Thread Communicationn.pptx
Inter Thread Communicationn.pptx
SelvakumarNSNS
 
Strings
StringsStrings
Strings
Mitali Chugh
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
Jasleen Kaur (Chandigarh University)
 
Member Function in C++
Member Function in C++ Member Function in C++
Member Function in C++
NikitaKaur10
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpp
rajshreemuthiah
 
CONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGECONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGE
Ideal Eyes Business College
 

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)

IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
SweetytamannaMohapat
 
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
Quiz Club of PSG College of Arts & Science
 
State institute of educational technology
State institute of educational technologyState institute of educational technology
State institute of educational technology
vp5806484
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad LevelLDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDM & Mia eStudios
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
Search Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website SuccessSearch Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website Success
Muneeb Rana
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
Quiz Club of PSG College of Arts & Science
 
la storia dell'Inghilterra, letteratura inglese
la storia dell'Inghilterra, letteratura inglesela storia dell'Inghilterra, letteratura inglese
la storia dell'Inghilterra, letteratura inglese
LetiziaLucente
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
How to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 SalesHow to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 Sales
Celine George
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
SweetytamannaMohapat
 
State institute of educational technology
State institute of educational technologyState institute of educational technology
State institute of educational technology
vp5806484
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad LevelLDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDM & Mia eStudios
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptxPests of Rice: Damage, Identification, Life history, and Management.pptx
Pests of Rice: Damage, Identification, Life history, and Management.pptx
Arshad Shaikh
 
Search Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website SuccessSearch Engine Optimization (SEO) for Website Success
Search Engine Optimization (SEO) for Website Success
Muneeb Rana
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
la storia dell'Inghilterra, letteratura inglese
la storia dell'Inghilterra, letteratura inglesela storia dell'Inghilterra, letteratura inglese
la storia dell'Inghilterra, letteratura inglese
LetiziaLucente
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
How to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 SalesHow to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 Sales
Celine George
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 

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.