SlideShare a Scribd company logo
1 of 30
Download to read offline
 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 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
 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

What's hot (20)

Operators in python
Operators in pythonOperators in python
Operators in python
 
Python Modules
Python ModulesPython Modules
Python Modules
 
Python functions
Python functionsPython functions
Python functions
 
Python ppt
Python pptPython ppt
Python ppt
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Chapter 14 strings
Chapter 14 stringsChapter 14 strings
Chapter 14 strings
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
 
Python list
Python listPython list
Python list
 
Python strings presentation
Python strings presentationPython strings presentation
Python strings presentation
 
Python tuple
Python   tuplePython   tuple
Python tuple
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
 
Python set
Python setPython set
Python set
 
List in Python
List in PythonList in Python
List in Python
 
basic of desicion control statement in python
basic of  desicion control statement in pythonbasic of  desicion control statement in python
basic of desicion control statement in python
 
Tuple in python
Tuple in pythonTuple in python
Tuple in python
 
Python programming : Standard Input and Output
Python programming : Standard Input and OutputPython programming : Standard Input and Output
Python programming : Standard Input and Output
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
 

Similar to Python-02| Input, Output & Import

Os Vanrossum
Os VanrossumOs Vanrossum
Os Vanrossum
oscon2007
 
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
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptx
jovannyflex
 

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
 
Basic Concepts in Python
Basic Concepts in PythonBasic Concepts in Python
Basic Concepts in Python
 
Unit2 input output
Unit2 input outputUnit2 input output
Unit2 input output
 
INTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHONINTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHON
 
Python 3.pptx
Python 3.pptxPython 3.pptx
Python 3.pptx
 
Os Vanrossum
Os VanrossumOs Vanrossum
Os Vanrossum
 
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
 
MODULE. .pptx
MODULE.                              .pptxMODULE.                              .pptx
MODULE. .pptx
 
FSTREAM,ASSERT LIBRARY & CTYPE LIBRARY.
FSTREAM,ASSERT LIBRARY & CTYPE LIBRARY.FSTREAM,ASSERT LIBRARY & CTYPE LIBRARY.
FSTREAM,ASSERT LIBRARY & CTYPE LIBRARY.
 
Python 3000
Python 3000Python 3000
Python 3000
 
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
 
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
 
Advanced Web Technology ass.pdf
Advanced Web Technology ass.pdfAdvanced Web Technology ass.pdf
Advanced Web Technology ass.pdf
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdf
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptx
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptx
 
Matlab Basic Tutorial
Matlab Basic TutorialMatlab Basic Tutorial
Matlab Basic Tutorial
 
Python lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce functionPython lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce function
 
Functions.docx
Functions.docxFunctions.docx
Functions.docx
 
Phyton Learning extracts
Phyton Learning extracts Phyton Learning extracts
Phyton Learning extracts
 

More from Mohd Sajjad

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
 
Python-03| Data types
Python-03| Data typesPython-03| Data types
Python-03| Data types
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
 
Python-00 | Introduction and installing
Python-00 | Introduction and installingPython-00 | Introduction and installing
Python-00 | Introduction and installing
 
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
 
SNMP Protocol
SNMP ProtocolSNMP Protocol
SNMP Protocol
 

Recently uploaded

Recently uploaded (20)

Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 

Python-02| Input, Output & Import

  • 1.
  • 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(“#”)
  • 15.
  • 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
  • 28.
  • 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.