SlideShare a Scribd company logo
3
Most read
4
Most read
5
Most read
Standard Input & Output
Team Emertxe
Output Statements
Output Statements
Print()
 print(), when called simply throws the cursor to the next line
 Means, a blank line will be displayed
Output Statements
Print(“string”)
Example Output
print()
Prints the 'n' character
print("Hello") Hello
print('Hello') Hello
print("Hello nWorld") Hello
World
print("Hello tWorld") Hello World
print("Hello nWorld") Hello nWorld
print(3 * 'Hello') HelloHelloHello
print("Hello"+"World") HelloWorld
print("Hello","World") Hello World
Output Statements
Print(variable list)
Example Output
a, b = 1, 2
print(a, b) 1 2
print(a, b, sep=",") 1,2
print(a, b, sep=':') 1:2
print(a, b, sep='---') 1---2
print("Hello", end="")
print("World")
HelloWorld
print("Hello", end="t")
print("World")
Hello World
Output Statements
Print(object)
Example Output
lst = [10, 'A', "Hai"]
print(lst) [10, 'A', 'Hai']
d = {10: "Ram", 20: "Amar"}
print(d)
{10: 'Ram', 20: 'Amar'}

Objects like list, tuples or dictionaries can be displayed
Output Statements
Print(“string”, variable list)
Example Output
a = 2
print(a, ": Even Number")
print("You typed", a, "as Input")
2 : Even Number
You typed 2 as Input
Output Statements
Print(formatted string)
Syntax: print("formatted string" % (varaible list))
Example Output
a = 10
print("The value of a: %i" % a) The value of a: 10
a, b = 10, 20
print("a: %dtb: %d" % (a, b))
a: 10 b: 20
name = "Ram"
print("Hai %s" % name)
print("Hai (%20s)" % name)
print("Hai (%-20s)" % name)
Hai Ram
Hai ( Ram)
Hai (Ram )
print("%c" % name[2]) m
print("%s" % name[0:2]) Ra
num = 123.345727
print("Num: %f" % num)
print("Num: %8.2f" % num)
Num: 123.345727
Num: 123.35
Output Statements
Print(formatted string)
Syntax: print("formatted string" % (varaible list))
Example Output
a, b, c = 1, 2, 3
print("First= {0}". format(a))
print("First= {0}, Second= {1}". format(a, b))
print("First= {one}, Second= {two}". format(one=a, two=b))
print("First= {}, Second= {}". format(a, b))
First= 1
First= 1, Second= 2
First= 1, Second= 2
First= 1, Second= 2
name, salary = "Ram", 123.45
print("Hello {0}, your salary: {1}". format(name, salary))
print("Hello {n}, your salary: {s}". format(n=name, s=salary))
print("Hello {:s}, your salary: {:.2f}". format(name, salary))
print("Hello %s, your salary: %.2f" % (name, salary))
Hello Ram, your salary: 123.45
Hello Ram, your salary: 123.45
Hello Ram, your salary: 123.45
Hello Ram, your salary: 123.45
Input Statements
Input Statements
Input()
Example
str = input()
print(str)
str = input("Enter the name: ")
print(str)
a = int(input("Enter the number: "))
print(a)
b = float(input("Enter the float number: "))
print(b)
Command Line Arguments
CLA
Example
1 #To display CLA
2
3 import sys
4
5 #Get the no. of CLA
6 n = len(sys.argv)
7
8 #Get the arguments
9 args = sys.argv
10
11 #Print the 'n'
12 print("No. Of CLA: ", n)
13
14 #print the arguments in one shot
15 print(args)
16
17 #Print the arguments one by one
18 for i in args:
19 print(i)
CLA
Parsing CLA
●
argparse module is useful to develop user-friendly programs
●
This module automatically generates help and usage messages
●
May also display appropriate error messages
CLA
Parsing CLA: Steps
● Step-1: Import argparse module
import argparse
● Step-2: Create an Object of ArgumentParser
parser = argparse.ArgumentParser(description="This program displays square of two numbers")
● Step-2a: If programmer does not want to display description, then above step can
be skipped
parser = argparse.ArgumentParser()
● Step-3: Add the arguments to the parser
parser.add_argument("num", type=int, help="Enter only int number.")
● Step-4: Retrieve the arguments
args = parser.parse_args()
● Step-4: Retrieve the arguments
● Step-5: Access the arguments
args.num
THANK YOU

More Related Content

What's hot (20)

PPTX
File handling in Python
Megha V
 
PPTX
Basics of Object Oriented Programming in Python
Sujith Kumar
 
PPTX
While , For , Do-While Loop
Abhishek Choksi
 
PDF
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Edureka!
 
PPTX
Print input-presentation
Martin McBride
 
PDF
Python programming : Control statements
Emertxe Information Technologies Pvt Ltd
 
PPTX
Python variables and data types.pptx
AkshayAggarwal79
 
PDF
Python programming : Files
Emertxe Information Technologies Pvt Ltd
 
PDF
Introduction to Python
Mohammed Sikander
 
PPTX
Variables in python
Jaya Kumari
 
PPT
Enumerated data types in C
Arpana shree
 
PPT
structure and union
student
 
PPTX
Library functions in c++
Neeru Mittal
 
PDF
Php array
Nikul Shah
 
PPT
File handling in c
David Livingston J
 
PDF
Arrays in python
moazamali28
 
PPTX
Functions in c language
tanmaymodi4
 
PPTX
07. Virtual Functions
Haresh Jaiswal
 
PPTX
Python: Modules and Packages
Damian T. Gordon
 
PPSX
Modules and packages in python
TMARAGATHAM
 
File handling in Python
Megha V
 
Basics of Object Oriented Programming in Python
Sujith Kumar
 
While , For , Do-While Loop
Abhishek Choksi
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Edureka!
 
Print input-presentation
Martin McBride
 
Python programming : Control statements
Emertxe Information Technologies Pvt Ltd
 
Python variables and data types.pptx
AkshayAggarwal79
 
Python programming : Files
Emertxe Information Technologies Pvt Ltd
 
Introduction to Python
Mohammed Sikander
 
Variables in python
Jaya Kumari
 
Enumerated data types in C
Arpana shree
 
structure and union
student
 
Library functions in c++
Neeru Mittal
 
Php array
Nikul Shah
 
File handling in c
David Livingston J
 
Arrays in python
moazamali28
 
Functions in c language
tanmaymodi4
 
07. Virtual Functions
Haresh Jaiswal
 
Python: Modules and Packages
Damian T. Gordon
 
Modules and packages in python
TMARAGATHAM
 

Similar to Python programming : Standard Input and Output (20)

PPTX
inputoutput.pptx
Venkateswara Babu Ravipati
 
PPTX
Python basics
NexThoughts Technologies
 
PPTX
C Programming Language Part 11
Rumman Ansari
 
DOCX
Oracle SQL
Anar Godjaev
 
PDF
The Ring programming language version 1.6 book - Part 26 of 189
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.9 book - Part 31 of 210
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.8 book - Part 29 of 202
Mahmoud Samir Fayed
 
PDF
Foxpro (1)
piyushrajsinha
 
PPTX
Python crush course
Mohammed El Rafie Tarabay
 
PPTX
Python 101++: Let's Get Down to Business!
Paige Bailey
 
PDF
The Ring programming language version 1.10 book - Part 28 of 212
Mahmoud Samir Fayed
 
KEY
Clojure入門
Naoyuki Kakuda
 
PPTX
Basic python programs
RaginiJain21
 
PDF
The Ring programming language version 1.8 book - Part 94 of 202
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.3 book - Part 20 of 184
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.2 book - Part 35 of 181
Mahmoud Samir Fayed
 
PPTX
String_C.pptx
HARSHITHA EBBALI
 
PDF
The Ring programming language version 1.6 book - Part 22 of 189
Mahmoud Samir Fayed
 
DOC
Rumus VB-1
T. Astari
 
PDF
The Ring programming language version 1.8 book - Part 46 of 202
Mahmoud Samir Fayed
 
inputoutput.pptx
Venkateswara Babu Ravipati
 
C Programming Language Part 11
Rumman Ansari
 
Oracle SQL
Anar Godjaev
 
The Ring programming language version 1.6 book - Part 26 of 189
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 31 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 29 of 202
Mahmoud Samir Fayed
 
Foxpro (1)
piyushrajsinha
 
Python crush course
Mohammed El Rafie Tarabay
 
Python 101++: Let's Get Down to Business!
Paige Bailey
 
The Ring programming language version 1.10 book - Part 28 of 212
Mahmoud Samir Fayed
 
Clojure入門
Naoyuki Kakuda
 
Basic python programs
RaginiJain21
 
The Ring programming language version 1.8 book - Part 94 of 202
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 20 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 35 of 181
Mahmoud Samir Fayed
 
String_C.pptx
HARSHITHA EBBALI
 
The Ring programming language version 1.6 book - Part 22 of 189
Mahmoud Samir Fayed
 
Rumus VB-1
T. Astari
 
The Ring programming language version 1.8 book - Part 46 of 202
Mahmoud Samir Fayed
 
Ad

More from Emertxe Information Technologies Pvt Ltd (20)

Ad

Recently uploaded (20)

PDF
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
PDF
Understanding AI Optimization AIO, LLMO, and GEO
CoDigital
 
PDF
Bridging CAD, IBM TRIRIGA & GIS with FME: The Portland Public Schools Case
Safe Software
 
PDF
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
PDF
Pipeline Industry IoT - Real Time Data Monitoring
Safe Software
 
PDF
Quantum Threats Are Closer Than You Think – Act Now to Stay Secure
WSO2
 
PPTX
Wondershare Filmora Crack Free Download 2025
josanj305
 
PDF
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
PDF
How to Comply With Saudi Arabia’s National Cybersecurity Regulations.pdf
Bluechip Advanced Technologies
 
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
PDF
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
PDF
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
PDF
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
PPTX
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
PDF
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
PPSX
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
PDF
“A Re-imagination of Embedded Vision System Design,” a Presentation from Imag...
Edge AI and Vision Alliance
 
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
Understanding AI Optimization AIO, LLMO, and GEO
CoDigital
 
Bridging CAD, IBM TRIRIGA & GIS with FME: The Portland Public Schools Case
Safe Software
 
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
Pipeline Industry IoT - Real Time Data Monitoring
Safe Software
 
Quantum Threats Are Closer Than You Think – Act Now to Stay Secure
WSO2
 
Wondershare Filmora Crack Free Download 2025
josanj305
 
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
How to Comply With Saudi Arabia’s National Cybersecurity Regulations.pdf
Bluechip Advanced Technologies
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
“A Re-imagination of Embedded Vision System Design,” a Presentation from Imag...
Edge AI and Vision Alliance
 

Python programming : Standard Input and Output

  • 1. Standard Input & Output Team Emertxe
  • 3. Output Statements Print()  print(), when called simply throws the cursor to the next line  Means, a blank line will be displayed
  • 4. Output Statements Print(“string”) Example Output print() Prints the 'n' character print("Hello") Hello print('Hello') Hello print("Hello nWorld") Hello World print("Hello tWorld") Hello World print("Hello nWorld") Hello nWorld print(3 * 'Hello') HelloHelloHello print("Hello"+"World") HelloWorld print("Hello","World") Hello World
  • 5. Output Statements Print(variable list) Example Output a, b = 1, 2 print(a, b) 1 2 print(a, b, sep=",") 1,2 print(a, b, sep=':') 1:2 print(a, b, sep='---') 1---2 print("Hello", end="") print("World") HelloWorld print("Hello", end="t") print("World") Hello World
  • 6. Output Statements Print(object) Example Output lst = [10, 'A', "Hai"] print(lst) [10, 'A', 'Hai'] d = {10: "Ram", 20: "Amar"} print(d) {10: 'Ram', 20: 'Amar'}  Objects like list, tuples or dictionaries can be displayed
  • 7. Output Statements Print(“string”, variable list) Example Output a = 2 print(a, ": Even Number") print("You typed", a, "as Input") 2 : Even Number You typed 2 as Input
  • 8. Output Statements Print(formatted string) Syntax: print("formatted string" % (varaible list)) Example Output a = 10 print("The value of a: %i" % a) The value of a: 10 a, b = 10, 20 print("a: %dtb: %d" % (a, b)) a: 10 b: 20 name = "Ram" print("Hai %s" % name) print("Hai (%20s)" % name) print("Hai (%-20s)" % name) Hai Ram Hai ( Ram) Hai (Ram ) print("%c" % name[2]) m print("%s" % name[0:2]) Ra num = 123.345727 print("Num: %f" % num) print("Num: %8.2f" % num) Num: 123.345727 Num: 123.35
  • 9. Output Statements Print(formatted string) Syntax: print("formatted string" % (varaible list)) Example Output a, b, c = 1, 2, 3 print("First= {0}". format(a)) print("First= {0}, Second= {1}". format(a, b)) print("First= {one}, Second= {two}". format(one=a, two=b)) print("First= {}, Second= {}". format(a, b)) First= 1 First= 1, Second= 2 First= 1, Second= 2 First= 1, Second= 2 name, salary = "Ram", 123.45 print("Hello {0}, your salary: {1}". format(name, salary)) print("Hello {n}, your salary: {s}". format(n=name, s=salary)) print("Hello {:s}, your salary: {:.2f}". format(name, salary)) print("Hello %s, your salary: %.2f" % (name, salary)) Hello Ram, your salary: 123.45 Hello Ram, your salary: 123.45 Hello Ram, your salary: 123.45 Hello Ram, your salary: 123.45
  • 11. Input Statements Input() Example str = input() print(str) str = input("Enter the name: ") print(str) a = int(input("Enter the number: ")) print(a) b = float(input("Enter the float number: ")) print(b)
  • 13. CLA Example 1 #To display CLA 2 3 import sys 4 5 #Get the no. of CLA 6 n = len(sys.argv) 7 8 #Get the arguments 9 args = sys.argv 10 11 #Print the 'n' 12 print("No. Of CLA: ", n) 13 14 #print the arguments in one shot 15 print(args) 16 17 #Print the arguments one by one 18 for i in args: 19 print(i)
  • 14. CLA Parsing CLA ● argparse module is useful to develop user-friendly programs ● This module automatically generates help and usage messages ● May also display appropriate error messages
  • 15. CLA Parsing CLA: Steps ● Step-1: Import argparse module import argparse ● Step-2: Create an Object of ArgumentParser parser = argparse.ArgumentParser(description="This program displays square of two numbers") ● Step-2a: If programmer does not want to display description, then above step can be skipped parser = argparse.ArgumentParser() ● Step-3: Add the arguments to the parser parser.add_argument("num", type=int, help="Enter only int number.") ● Step-4: Retrieve the arguments args = parser.parse_args() ● Step-4: Retrieve the arguments ● Step-5: Access the arguments args.num