SlideShare a Scribd company logo
4
Most read
5
Most read
11
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

PDF
Operators in python
PDF
Python set
PPTX
Characterization of nanoparticles
PDF
Python programming : Arrays
PDF
Python programming : Files
PPTX
Arrays in c
PDF
Python-02| Input, Output & Import
Operators in python
Python set
Characterization of nanoparticles
Python programming : Arrays
Python programming : Files
Arrays in c
Python-02| Input, Output & Import

What's hot (20)

PDF
Datatypes in python
PPT
Operator Overloading
PDF
Strings in python
PPTX
Looping statement in python
PPTX
Python basics
PPTX
Basic Python Programming: Part 01 and Part 02
PPTX
Basic Concepts of OOPs (Object Oriented Programming in Java)
PPTX
String Manipulation in Python
PPTX
Python Programming Essentials - M24 - math module
DOC
Time and space complexity
PDF
Python libraries
PPTX
Tcp/ip server sockets
PDF
Object oriented programming c++
PDF
C++ OOPS Concept
PPTX
CLASS OBJECT AND INHERITANCE IN PYTHON
PPTX
Constructor overloading & method overloading
PPTX
Constructors in C++
PPTX
Introduction to python
Datatypes in python
Operator Overloading
Strings in python
Looping statement in python
Python basics
Basic Python Programming: Part 01 and Part 02
Basic Concepts of OOPs (Object Oriented Programming in Java)
String Manipulation in Python
Python Programming Essentials - M24 - math module
Time and space complexity
Python libraries
Tcp/ip server sockets
Object oriented programming c++
C++ OOPS Concept
CLASS OBJECT AND INHERITANCE IN PYTHON
Constructor overloading & method overloading
Constructors in C++
Introduction to python
Ad

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

PPTX
inputoutput.pptx
PPTX
PPTX
C Programming Language Part 11
DOCX
Oracle SQL
PDF
The Ring programming language version 1.6 book - Part 26 of 189
PDF
The Ring programming language version 1.9 book - Part 31 of 210
PDF
The Ring programming language version 1.8 book - Part 29 of 202
PDF
Foxpro (1)
PPTX
Python crush course
PPTX
Python 101++: Let's Get Down to Business!
PDF
The Ring programming language version 1.10 book - Part 28 of 212
KEY
Clojure入門
PPTX
Basic python programs
PDF
The Ring programming language version 1.8 book - Part 94 of 202
PDF
The Ring programming language version 1.5.3 book - Part 20 of 184
PDF
The Ring programming language version 1.5.2 book - Part 35 of 181
PPTX
String_C.pptx
PDF
The Ring programming language version 1.6 book - Part 22 of 189
DOC
Rumus VB-1
PDF
The Ring programming language version 1.8 book - Part 46 of 202
inputoutput.pptx
C Programming Language Part 11
Oracle SQL
The Ring programming language version 1.6 book - Part 26 of 189
The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.8 book - Part 29 of 202
Foxpro (1)
Python crush course
Python 101++: Let's Get Down to Business!
The Ring programming language version 1.10 book - Part 28 of 212
Clojure入門
Basic python programs
The Ring programming language version 1.8 book - Part 94 of 202
The Ring programming language version 1.5.3 book - Part 20 of 184
The Ring programming language version 1.5.2 book - Part 35 of 181
String_C.pptx
The Ring programming language version 1.6 book - Part 22 of 189
Rumus VB-1
The Ring programming language version 1.8 book - Part 46 of 202
Ad

More from Emertxe Information Technologies Pvt Ltd (20)

Recently uploaded (20)

PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Electronic commerce courselecture one. Pdf
PDF
Modernizing your data center with Dell and AMD
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Cloud computing and distributed systems.
PPTX
A Presentation on Artificial Intelligence
PDF
cuic standard and advanced reporting.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Unlocking AI with Model Context Protocol (MCP)
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
“AI and Expert System Decision Support & Business Intelligence Systems”
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Spectral efficient network and resource selection model in 5G networks
Network Security Unit 5.pdf for BCA BBA.
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Electronic commerce courselecture one. Pdf
Modernizing your data center with Dell and AMD
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
MYSQL Presentation for SQL database connectivity
Cloud computing and distributed systems.
A Presentation on Artificial Intelligence
cuic standard and advanced reporting.pdf

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