SlideShare a Scribd company logo
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

What's hot (20)

Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
 
Boolean and conditional logic in Python
Boolean and conditional logic in PythonBoolean and conditional logic in Python
Boolean and conditional logic in Python
 
C if else
C if elseC if else
C if else
 
Chapter 16 Dictionaries
Chapter 16 DictionariesChapter 16 Dictionaries
Chapter 16 Dictionaries
 
String Manipulation in Python
String Manipulation in PythonString Manipulation in Python
String Manipulation in Python
 
Python programming : List and tuples
Python programming : List and tuplesPython programming : List and tuples
Python programming : List and tuples
 
Immutable vs mutable data types in python
Immutable vs mutable data types in pythonImmutable vs mutable data types in python
Immutable vs mutable data types in python
 
Strings in C
Strings in CStrings in C
Strings in C
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
Basic data types in python
Basic data types in pythonBasic data types in python
Basic data types in python
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
Chapter 07 inheritance
Chapter 07 inheritanceChapter 07 inheritance
Chapter 07 inheritance
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
 
Unit 3. Input and Output
Unit 3. Input and OutputUnit 3. Input and Output
Unit 3. Input and Output
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 

Similar to Python programming : Standard Input and Output

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

inputoutput.pptx
inputoutput.pptxinputoutput.pptx
inputoutput.pptx
 
Python basics
Python basicsPython basics
Python basics
 
C Programming Language Part 11
C Programming Language Part 11C Programming Language Part 11
C Programming Language Part 11
 
Oracle SQL
Oracle SQLOracle SQL
Oracle SQL
 
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
 
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
 
The Ring programming language version 1.8 book - Part 29 of 202
The Ring programming language version 1.8 book - Part 29 of 202The Ring programming language version 1.8 book - Part 29 of 202
The Ring programming language version 1.8 book - Part 29 of 202
 
Foxpro (1)
Foxpro (1)Foxpro (1)
Foxpro (1)
 
Python crush course
Python crush coursePython crush course
Python crush course
 
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!
 
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
 
Clojure入門
Clojure入門Clojure入門
Clojure入門
 
Basic python programs
Basic python programsBasic python programs
Basic python programs
 
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
 
The Ring programming language version 1.5.3 book - Part 20 of 184
The Ring programming language version 1.5.3 book - Part 20 of 184The Ring programming language version 1.5.3 book - Part 20 of 184
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
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
 
String_C.pptx
String_C.pptxString_C.pptx
String_C.pptx
 
The Ring programming language version 1.6 book - Part 22 of 189
The Ring programming language version 1.6 book - Part 22 of 189The Ring programming language version 1.6 book - Part 22 of 189
The Ring programming language version 1.6 book - Part 22 of 189
 
Rumus VB-1
Rumus VB-1Rumus VB-1
Rumus VB-1
 
The Ring programming language version 1.8 book - Part 46 of 202
The Ring programming language version 1.8 book - Part 46 of 202The Ring programming language version 1.8 book - Part 46 of 202
The Ring programming language version 1.8 book - Part 46 of 202
 

More from Emertxe Information Technologies Pvt Ltd

More from Emertxe Information Technologies Pvt Ltd (20)

premium post (1).pdf
premium post (1).pdfpremium post (1).pdf
premium post (1).pdf
 
Career Transition (1).pdf
Career Transition (1).pdfCareer Transition (1).pdf
Career Transition (1).pdf
 
10_isxdigit.pdf
10_isxdigit.pdf10_isxdigit.pdf
10_isxdigit.pdf
 
01_student_record.pdf
01_student_record.pdf01_student_record.pdf
01_student_record.pdf
 
02_swap.pdf
02_swap.pdf02_swap.pdf
02_swap.pdf
 
01_sizeof.pdf
01_sizeof.pdf01_sizeof.pdf
01_sizeof.pdf
 
07_product_matrix.pdf
07_product_matrix.pdf07_product_matrix.pdf
07_product_matrix.pdf
 
06_sort_names.pdf
06_sort_names.pdf06_sort_names.pdf
06_sort_names.pdf
 
05_fragments.pdf
05_fragments.pdf05_fragments.pdf
05_fragments.pdf
 
04_magic_square.pdf
04_magic_square.pdf04_magic_square.pdf
04_magic_square.pdf
 
03_endianess.pdf
03_endianess.pdf03_endianess.pdf
03_endianess.pdf
 
02_variance.pdf
02_variance.pdf02_variance.pdf
02_variance.pdf
 
01_memory_manager.pdf
01_memory_manager.pdf01_memory_manager.pdf
01_memory_manager.pdf
 
09_nrps.pdf
09_nrps.pdf09_nrps.pdf
09_nrps.pdf
 
11_pangram.pdf
11_pangram.pdf11_pangram.pdf
11_pangram.pdf
 
10_combinations.pdf
10_combinations.pdf10_combinations.pdf
10_combinations.pdf
 
08_squeeze.pdf
08_squeeze.pdf08_squeeze.pdf
08_squeeze.pdf
 
07_strtok.pdf
07_strtok.pdf07_strtok.pdf
07_strtok.pdf
 
06_reverserec.pdf
06_reverserec.pdf06_reverserec.pdf
06_reverserec.pdf
 
05_reverseiter.pdf
05_reverseiter.pdf05_reverseiter.pdf
05_reverseiter.pdf
 

Recently uploaded

Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 

Recently uploaded (20)

GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT Professionals
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 

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