SlideShare a Scribd company logo
Input and output
statements
Python provides numerous built-in functions that are readily
available to us at the Python prompt.
Some of the functions like input() and print() are widely used for
standard input and output operations respectively.
Let us see the input section first.
2
Input statements
To allow flexibility, we might want to take the input from the
user. In Python, we have the input() function to allow this.
The syntax for input() is:
input([prompt])
where [prompt] is the string we wish to display on the
screen. It is optional.
3
● When input() function executes program flow will be stopped until
the user has given an input.
● The text or message display on the output screen to ask a user to
enter input value is optional i.e. the prompt, will be printed on the
screen is optional.
● Whatever you enter as input, input function convert it into a string. if
you enter an integer value still input() function convert it into a string.
4
How the input function works in Python :
5
Example 1
>>> num =
input('Enter a
number: ')
Enter a number: 10
>>> num
'10'
Example 2
x=input('enter your
name:')
enter your name:anu
>>> print(x)
anu
This same operation can be
performed using the eval()
function. But eval takes it further.
It can evaluate even expressions,
provided the input is a string.
Always use string as argument
for eval().
6
>>> int('2+3')
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
int('2+3')
ValueError: invalid literal for int() with base
10: '2+3'
>>> eval('2+3')
5
eval() for input
Data Type conversions
The process of converting the value of one data type
(integer, string, float, etc.) to another data type is called
type conversion. Python has two types of type
conversion.
1. Implicit Type Conversion
2. Explicit Type Conversion
7
In Implicit type conversion, Python automatically converts
one data type to another data type. This process doesn't
need any user involvement.
Python promotes the conversion of the lower data type
(integer) to the higher data type (float) to avoid data loss.
See the Example 1 given below:
8
Implicit Type Conversion
Example 1
Example 2
As we can see from the output, we got TypeError. Python is not able to use
Implicit Conversion in such conditions.
10
In Explicit Type Conversion, users convert the data type of
an object to required data type.
This type of conversion is also called typecasting because
the user casts (changes) the data type of the objects.
Casting in python is therefore done using constructor
functions:
11
Explicit Type Conversion
int() - constructs an integer
number from an integer literal, a
float literal (by rounding down
to the previous whole number),
or a string literal (providing the
string represents a whole
number)
12
int()
float() - constructs a float
number from an integer
literal, a float literal or a
string literal (providing the
string represents a float or
an integer)
13
float()
str() - constructs a string from a
wide variety of data types,
including strings, integer literals
and float literals.
14
str()
Key Points to Remember
1. Type Conversion is the conversion of object from one data type to another data typ
2. Implicit Type Conversion is automatically performed by the Python interpreter.
3. Python avoids the loss of data in Implicit Type Conversion.
4. Explicit Type Conversion is also called Type Casting, the data types of objects are
converted using predefined functions by the user.
5. In Type Casting, loss of data may occur as we enforce the object to a specific data
type.
15
16

More Related Content

What's hot

Generic programming and concepts that should be in C++
Generic programming and concepts that should be in C++Generic programming and concepts that should be in C++
Generic programming and concepts that should be in C++
Anton Kolotaev
 
Python recursion
Python recursionPython recursion
Python recursion
Prof. Dr. K. Adisesha
 
Dynamic Polymorphism in C++
Dynamic Polymorphism in C++Dynamic Polymorphism in C++
Dynamic Polymorphism in C++
Dharmisha Sharma
 
Static and const members
Static and const membersStatic and const members
Static and const members
mohamed sikander
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
amiable_indian
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
Sujith Kumar
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
avikdhupar
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
Emertxe Information Technologies Pvt Ltd
 
C introduction by thooyavan
C introduction by  thooyavanC introduction by  thooyavan
C introduction by thooyavan
Thooyavan Venkatachalam
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
Nowell Strite
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
Mohammed Sikander
 
Python programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsPython programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operations
Megha V
 
Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
Mohammed Sikander
 
Standard data-types-in-py
Standard data-types-in-pyStandard data-types-in-py
Standard data-types-in-py
Priyanshu Sengar
 
Python basic
Python basicPython basic
Python basic
Saifuddin Kaijar
 
Python_in_Detail
Python_in_DetailPython_in_Detail
Python_in_Detail
MAHALAKSHMI P
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
Mahender Boda
 
Java interfaces & abstract classes
Java interfaces & abstract classesJava interfaces & abstract classes
Java interfaces & abstract classes
Shreyans Pathak
 
The tests are trying to tell you something@VoxxedBucharest.pptx
The tests are trying to tell you something@VoxxedBucharest.pptxThe tests are trying to tell you something@VoxxedBucharest.pptx
The tests are trying to tell you something@VoxxedBucharest.pptx
Victor Rentea
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
Ayshwarya Baburam
 

What's hot (20)

Generic programming and concepts that should be in C++
Generic programming and concepts that should be in C++Generic programming and concepts that should be in C++
Generic programming and concepts that should be in C++
 
Python recursion
Python recursionPython recursion
Python recursion
 
Dynamic Polymorphism in C++
Dynamic Polymorphism in C++Dynamic Polymorphism in C++
Dynamic Polymorphism in C++
 
Static and const members
Static and const membersStatic and const members
Static and const members
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 
C introduction by thooyavan
C introduction by  thooyavanC introduction by  thooyavan
C introduction by thooyavan
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
 
Python programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsPython programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operations
 
Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
 
Standard data-types-in-py
Standard data-types-in-pyStandard data-types-in-py
Standard data-types-in-py
 
Python basic
Python basicPython basic
Python basic
 
Python_in_Detail
Python_in_DetailPython_in_Detail
Python_in_Detail
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
 
Java interfaces & abstract classes
Java interfaces & abstract classesJava interfaces & abstract classes
Java interfaces & abstract classes
 
The tests are trying to tell you something@VoxxedBucharest.pptx
The tests are trying to tell you something@VoxxedBucharest.pptxThe tests are trying to tell you something@VoxxedBucharest.pptx
The tests are trying to tell you something@VoxxedBucharest.pptx
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 

Similar to Input and Output Statements.pdf

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
 
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdfpython-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
KosmikTech1
 
Data Type Conversion in C++
Data Type Conversion in C++Data Type Conversion in C++
Data Type Conversion in C++
Danial Mirza
 
GE3151 UNIT II Study material .pdf
GE3151 UNIT II Study material .pdfGE3151 UNIT II Study material .pdf
GE3151 UNIT II Study material .pdf
Asst.prof M.Gokilavani
 
Python (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizePython (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualize
IruolagbePius
 
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
 
Python_programming.pptx
Python_programming.pptxPython_programming.pptx
Python_programming.pptx
ShaluChaudhary42
 
python
pythonpython
python
ultragamer6
 
Python by Rj
Python by RjPython by Rj
Python introduction towards data science
Python introduction towards data sciencePython introduction towards data science
Python introduction towards data science
deepak teja
 
Unit2 input output
Unit2 input outputUnit2 input output
Unit2 input output
deepak kumbhar
 
Review Python
Review PythonReview Python
Review Python
ManishTiwari326
 
1. PGA2.0-Python Programming-Intro to Python.pptx
1. PGA2.0-Python Programming-Intro to Python.pptx1. PGA2.0-Python Programming-Intro to Python.pptx
1. PGA2.0-Python Programming-Intro to Python.pptx
Rakesh Ahuja
 
python ppt | Python Course In Ghaziabad | Scode Network Institute
python ppt | Python Course In Ghaziabad | Scode Network Institutepython ppt | Python Course In Ghaziabad | Scode Network Institute
python ppt | Python Course In Ghaziabad | Scode Network Institute
Scode Network Institute
 
gdscpython.pdf
gdscpython.pdfgdscpython.pdf
gdscpython.pdf
workvishalkumarmahat
 
Fundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programmingFundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programming
LidetAdmassu
 
Welcome to python workshop
Welcome to python workshopWelcome to python workshop
Welcome to python workshop
Mukul Kirti Verma
 
Python Decision Making And Loops.pdf
Python Decision Making And Loops.pdfPython Decision Making And Loops.pdf
Python Decision Making And Loops.pdf
NehaSpillai1
 
Python ppt
Python pptPython ppt

Similar to Input and Output Statements.pdf (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
 
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdfpython-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
 
Data Type Conversion in C++
Data Type Conversion in C++Data Type Conversion in C++
Data Type Conversion in C++
 
GE3151 UNIT II Study material .pdf
GE3151 UNIT II Study material .pdfGE3151 UNIT II Study material .pdf
GE3151 UNIT II Study material .pdf
 
Python (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizePython (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualize
 
Basic Concepts in Python
Basic Concepts in PythonBasic Concepts in Python
Basic Concepts in Python
 
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
 
Python_programming.pptx
Python_programming.pptxPython_programming.pptx
Python_programming.pptx
 
python
pythonpython
python
 
Python by Rj
Python by RjPython by Rj
Python by Rj
 
Python introduction towards data science
Python introduction towards data sciencePython introduction towards data science
Python introduction towards data science
 
Unit2 input output
Unit2 input outputUnit2 input output
Unit2 input output
 
Review Python
Review PythonReview Python
Review Python
 
1. PGA2.0-Python Programming-Intro to Python.pptx
1. PGA2.0-Python Programming-Intro to Python.pptx1. PGA2.0-Python Programming-Intro to Python.pptx
1. PGA2.0-Python Programming-Intro to Python.pptx
 
python ppt | Python Course In Ghaziabad | Scode Network Institute
python ppt | Python Course In Ghaziabad | Scode Network Institutepython ppt | Python Course In Ghaziabad | Scode Network Institute
python ppt | Python Course In Ghaziabad | Scode Network Institute
 
gdscpython.pdf
gdscpython.pdfgdscpython.pdf
gdscpython.pdf
 
Fundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programmingFundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programming
 
Welcome to python workshop
Welcome to python workshopWelcome to python workshop
Welcome to python workshop
 
Python Decision Making And Loops.pdf
Python Decision Making And Loops.pdfPython Decision Making And Loops.pdf
Python Decision Making And Loops.pdf
 
Python ppt
Python pptPython ppt
Python ppt
 

More from ZahraAbdulAhmad

COOPERATIVE SOCIETY.pdf
COOPERATIVE SOCIETY.pdfCOOPERATIVE SOCIETY.pdf
COOPERATIVE SOCIETY.pdf
ZahraAbdulAhmad
 
One Person Company.pdf
One Person Company.pdfOne Person Company.pdf
One Person Company.pdf
ZahraAbdulAhmad
 
Were not Afraid to Die... If we can all be Together..pdf
Were not Afraid to Die... If we can all be Together..pdfWere not Afraid to Die... If we can all be Together..pdf
Were not Afraid to Die... If we can all be Together..pdf
ZahraAbdulAhmad
 
Getting Started With Python.pdf
Getting Started With Python.pdfGetting Started With Python.pdf
Getting Started With Python.pdf
ZahraAbdulAhmad
 
Computer System- (1).pdf
Computer System- (1).pdfComputer System- (1).pdf
Computer System- (1).pdf
ZahraAbdulAhmad
 
WORLD HEALTH ORGANIZATION.pdf
WORLD HEALTH ORGANIZATION.pdfWORLD HEALTH ORGANIZATION.pdf
WORLD HEALTH ORGANIZATION.pdf
ZahraAbdulAhmad
 
Robotics IP (1).pdf
Robotics IP  (1).pdfRobotics IP  (1).pdf
Robotics IP (1).pdf
ZahraAbdulAhmad
 
Types of Companies.pdf
Types of Companies.pdfTypes of Companies.pdf
Types of Companies.pdf
ZahraAbdulAhmad
 
Privatisation -bst.pdf
Privatisation -bst.pdfPrivatisation -bst.pdf
Privatisation -bst.pdf
ZahraAbdulAhmad
 
Collection of Data (Information from Local sources).pdf
Collection of Data (Information from Local sources).pdfCollection of Data (Information from Local sources).pdf
Collection of Data (Information from Local sources).pdf
ZahraAbdulAhmad
 

More from ZahraAbdulAhmad (10)

COOPERATIVE SOCIETY.pdf
COOPERATIVE SOCIETY.pdfCOOPERATIVE SOCIETY.pdf
COOPERATIVE SOCIETY.pdf
 
One Person Company.pdf
One Person Company.pdfOne Person Company.pdf
One Person Company.pdf
 
Were not Afraid to Die... If we can all be Together..pdf
Were not Afraid to Die... If we can all be Together..pdfWere not Afraid to Die... If we can all be Together..pdf
Were not Afraid to Die... If we can all be Together..pdf
 
Getting Started With Python.pdf
Getting Started With Python.pdfGetting Started With Python.pdf
Getting Started With Python.pdf
 
Computer System- (1).pdf
Computer System- (1).pdfComputer System- (1).pdf
Computer System- (1).pdf
 
WORLD HEALTH ORGANIZATION.pdf
WORLD HEALTH ORGANIZATION.pdfWORLD HEALTH ORGANIZATION.pdf
WORLD HEALTH ORGANIZATION.pdf
 
Robotics IP (1).pdf
Robotics IP  (1).pdfRobotics IP  (1).pdf
Robotics IP (1).pdf
 
Types of Companies.pdf
Types of Companies.pdfTypes of Companies.pdf
Types of Companies.pdf
 
Privatisation -bst.pdf
Privatisation -bst.pdfPrivatisation -bst.pdf
Privatisation -bst.pdf
 
Collection of Data (Information from Local sources).pdf
Collection of Data (Information from Local sources).pdfCollection of Data (Information from Local sources).pdf
Collection of Data (Information from Local sources).pdf
 

Recently uploaded

socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
aymanquadri279
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 

Recently uploaded (20)

socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 

Input and Output Statements.pdf

  • 2. Python provides numerous built-in functions that are readily available to us at the Python prompt. Some of the functions like input() and print() are widely used for standard input and output operations respectively. Let us see the input section first. 2
  • 3. Input statements To allow flexibility, we might want to take the input from the user. In Python, we have the input() function to allow this. The syntax for input() is: input([prompt]) where [prompt] is the string we wish to display on the screen. It is optional. 3
  • 4. ● When input() function executes program flow will be stopped until the user has given an input. ● The text or message display on the output screen to ask a user to enter input value is optional i.e. the prompt, will be printed on the screen is optional. ● Whatever you enter as input, input function convert it into a string. if you enter an integer value still input() function convert it into a string. 4 How the input function works in Python :
  • 5. 5 Example 1 >>> num = input('Enter a number: ') Enter a number: 10 >>> num '10' Example 2 x=input('enter your name:') enter your name:anu >>> print(x) anu
  • 6. This same operation can be performed using the eval() function. But eval takes it further. It can evaluate even expressions, provided the input is a string. Always use string as argument for eval(). 6 >>> int('2+3') Traceback (most recent call last): File "<pyshell#1>", line 1, in <module> int('2+3') ValueError: invalid literal for int() with base 10: '2+3' >>> eval('2+3') 5 eval() for input
  • 7. Data Type conversions The process of converting the value of one data type (integer, string, float, etc.) to another data type is called type conversion. Python has two types of type conversion. 1. Implicit Type Conversion 2. Explicit Type Conversion 7
  • 8. In Implicit type conversion, Python automatically converts one data type to another data type. This process doesn't need any user involvement. Python promotes the conversion of the lower data type (integer) to the higher data type (float) to avoid data loss. See the Example 1 given below: 8 Implicit Type Conversion
  • 10. Example 2 As we can see from the output, we got TypeError. Python is not able to use Implicit Conversion in such conditions. 10
  • 11. In Explicit Type Conversion, users convert the data type of an object to required data type. This type of conversion is also called typecasting because the user casts (changes) the data type of the objects. Casting in python is therefore done using constructor functions: 11 Explicit Type Conversion
  • 12. int() - constructs an integer number from an integer literal, a float literal (by rounding down to the previous whole number), or a string literal (providing the string represents a whole number) 12 int()
  • 13. float() - constructs a float number from an integer literal, a float literal or a string literal (providing the string represents a float or an integer) 13 float()
  • 14. str() - constructs a string from a wide variety of data types, including strings, integer literals and float literals. 14 str()
  • 15. Key Points to Remember 1. Type Conversion is the conversion of object from one data type to another data typ 2. Implicit Type Conversion is automatically performed by the Python interpreter. 3. Python avoids the loss of data in Implicit Type Conversion. 4. Explicit Type Conversion is also called Type Casting, the data types of objects are converted using predefined functions by the user. 5. In Type Casting, loss of data may occur as we enforce the object to a specific data type. 15
  • 16. 16