SlideShare a Scribd company logo
1 of 16
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") 2 : Even Number
You typed 2 as Input
print("You typed", a, "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" Hai Ram
print("Hai %s" % name) Hai ( Ram)
print("Hai (%20s)" % name) Hai (Ram )
print("Hai (%-20s)" % name)
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)) First= 1
print("First= {one}, Second= {two}". format(one=a, two=b)) First= 1, Second= 2
print("First= {}, Second= {}". format(a, b)) 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
6n = len(sys.argv)
7
8 #Get the arguments
9args = sys.argv
10
11 #Print the 'n'
12print("No. Of CLA: ", n)
13
14 #print the arguments in one shot
15print(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.")
args = parser.parse_args()
● Step-4: Retrieve the arguments
● Step-5: Access the arguments
args.num
THANK YOU

More Related Content

Similar to inputoutput.pptx

Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Paige Bailey
 
Practical File waale code.pdf
Practical File waale code.pdfPractical File waale code.pdf
Practical File waale code.pdfFriendsStationary
 
fds Practicle 1to 6 program.pdf
fds Practicle 1to 6 program.pdffds Practicle 1to 6 program.pdf
fds Practicle 1to 6 program.pdfGaneshPawar819187
 
Python real time tutorial
Python real time tutorialPython real time tutorial
Python real time tutorialRajeev Kumar
 
Session -5for students.pdf
Session -5for students.pdfSession -5for students.pdf
Session -5for students.pdfpriyanshusoni53
 
The Ring programming language version 1.6 book - Part 26 of 189
The Ring programming language version 1.6 book - Part 26 of 189The Ring programming language version 1.6 book - Part 26 of 189
The Ring programming language version 1.6 book - Part 26 of 189Mahmoud Samir Fayed
 
Preprocessor Programming
Preprocessor ProgrammingPreprocessor Programming
Preprocessor Programminglactrious
 
The Ring programming language version 1.10 book - Part 31 of 212
The Ring programming language version 1.10 book - Part 31 of 212The Ring programming language version 1.10 book - Part 31 of 212
The Ring programming language version 1.10 book - Part 31 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 28 of 212
The Ring programming language version 1.10 book - Part 28 of 212The Ring programming language version 1.10 book - Part 28 of 212
The Ring programming language version 1.10 book - Part 28 of 212Mahmoud Samir Fayed
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...AntareepMajumder
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]Abhishek Sinha
 
The Ring programming language version 1.5.2 book - Part 35 of 181
The Ring programming language version 1.5.2 book - Part 35 of 181The Ring programming language version 1.5.2 book - Part 35 of 181
The Ring programming language version 1.5.2 book - Part 35 of 181Mahmoud Samir Fayed
 
Python basic
Python basic Python basic
Python basic sewoo lee
 
The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210Mahmoud Samir Fayed
 
Print input-presentation
Print input-presentationPrint input-presentation
Print input-presentationMartin McBride
 

Similar to inputoutput.pptx (20)

Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!
 
Practical File waale code.pdf
Practical File waale code.pdfPractical File waale code.pdf
Practical File waale code.pdf
 
fds Practicle 1to 6 program.pdf
fds Practicle 1to 6 program.pdffds Practicle 1to 6 program.pdf
fds Practicle 1to 6 program.pdf
 
String_C.pptx
String_C.pptxString_C.pptx
String_C.pptx
 
Foxpro (1)
Foxpro (1)Foxpro (1)
Foxpro (1)
 
Practicle 1.docx
Practicle 1.docxPracticle 1.docx
Practicle 1.docx
 
Python real time tutorial
Python real time tutorialPython real time tutorial
Python real time tutorial
 
Session -5for students.pdf
Session -5for students.pdfSession -5for students.pdf
Session -5for students.pdf
 
Python crush course
Python crush coursePython crush course
Python crush course
 
The Ring programming language version 1.6 book - Part 26 of 189
The Ring programming language version 1.6 book - Part 26 of 189The Ring programming language version 1.6 book - Part 26 of 189
The Ring programming language version 1.6 book - Part 26 of 189
 
Preprocessor Programming
Preprocessor ProgrammingPreprocessor Programming
Preprocessor Programming
 
The Ring programming language version 1.10 book - Part 31 of 212
The Ring programming language version 1.10 book - Part 31 of 212The Ring programming language version 1.10 book - Part 31 of 212
The Ring programming language version 1.10 book - Part 31 of 212
 
The Ring programming language version 1.10 book - Part 28 of 212
The Ring programming language version 1.10 book - Part 28 of 212The Ring programming language version 1.10 book - Part 28 of 212
The Ring programming language version 1.10 book - Part 28 of 212
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
Struct examples
Struct examplesStruct examples
Struct examples
 
The Ring programming language version 1.5.2 book - Part 35 of 181
The Ring programming language version 1.5.2 book - Part 35 of 181The Ring programming language version 1.5.2 book - Part 35 of 181
The Ring programming language version 1.5.2 book - Part 35 of 181
 
Python basic
Python basic Python basic
Python basic
 
The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210
 
Print input-presentation
Print input-presentationPrint input-presentation
Print input-presentation
 

More from Venkateswara Babu Ravipati (12)

EG-Unit-2- Points.pptx
EG-Unit-2- Points.pptxEG-Unit-2- Points.pptx
EG-Unit-2- Points.pptx
 
EG- Unit 1.pptx
EG- Unit 1.pptxEG- Unit 1.pptx
EG- Unit 1.pptx
 
Chapter5.pptx
Chapter5.pptxChapter5.pptx
Chapter5.pptx
 
PP ECE A Sec UNIT-1.pptx
PP ECE A Sec UNIT-1.pptxPP ECE A Sec UNIT-1.pptx
PP ECE A Sec UNIT-1.pptx
 
python unit 2.pptx
python unit 2.pptxpython unit 2.pptx
python unit 2.pptx
 
Data types.pdf
Data types.pdfData types.pdf
Data types.pdf
 
types.pdf
types.pdftypes.pdf
types.pdf
 
6-Python-Recursion PPT.pptx
6-Python-Recursion PPT.pptx6-Python-Recursion PPT.pptx
6-Python-Recursion PPT.pptx
 
cad cam and robotics.pptx
cad cam and robotics.pptxcad cam and robotics.pptx
cad cam and robotics.pptx
 
unit3.pptx
unit3.pptxunit3.pptx
unit3.pptx
 
UNIT 2.pptx
UNIT 2.pptxUNIT 2.pptx
UNIT 2.pptx
 
Le and ne algorithms
Le and ne algorithmsLe and ne algorithms
Le and ne algorithms
 

Recently uploaded

MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGSIVASHANKAR N
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 

Recently uploaded (20)

MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 

inputoutput.pptx

  • 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") 2 : Even Number You typed 2 as Input print("You typed", a, "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" Hai Ram print("Hai %s" % name) Hai ( Ram) print("Hai (%20s)" % name) Hai (Ram ) print("Hai (%-20s)" % name) 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)) First= 1 print("First= {one}, Second= {two}". format(one=a, two=b)) First= 1, Second= 2 print("First= {}, Second= {}". format(a, b)) 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 6n = len(sys.argv) 7 8 #Get the arguments 9args = sys.argv 10 11 #Print the 'n' 12print("No. Of CLA: ", n) 13 14 #print the arguments in one shot 15print(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.") args = parser.parse_args() ● Step-4: Retrieve the arguments ● Step-5: Access the arguments args.num