0% found this document useful (0 votes)
25 views3 pages

Input and Output in Python

The document explains input and output in Python, highlighting the use of the print() function for output and the input() function for taking user data. It details how input is always received as a string and how to convert it to integers or floats using int() and float() respectively. Additionally, it provides examples of printing variables and combining input and output in a single program.

Uploaded by

Ali Raza
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views3 pages

Input and Output in Python

The document explains input and output in Python, highlighting the use of the print() function for output and the input() function for taking user data. It details how input is always received as a string and how to convert it to integers or floats using int() and float() respectively. Additionally, it provides examples of printing variables and combining input and output in a single program.

Uploaded by

Ali Raza
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Topic: Input and Output in Python

Definition
Input means taking data from the user.
Output means showing data on the screen.

1) Output in Python
Python uses the print() function to display anything on the screen.
Example
print("Hello World")
Output
Hello World
Important Point
print() is used to show:
• text
• numbers
• results
• variables

2) Input in Python
Python uses the input() function to take data from the user.
Example
name = input("Enter your name: ")
print(name)

Important Point
input() always takes data in string form.
3) Input as String
When we enter text, Python stores it as a string.
Example
city = input("Enter your city: ")
print("Your city is", city)

4) Input as Integer
If we want whole numbers, we use int() with input().
Example
age = int(input("Enter your age: "))
print("Your age is", age)
Note
int() converts string into integer.

5) Input as Float
If we want decimal numbers, we use float().
Example
price = float(input("Enter price: "))
print("Price is", price)
Note
float() converts string into decimal number.

6) Printing Variables
We can print variables in different ways.
Example 1
name = "Ali"
print(name)
Example 2
name = "Ali"
print("My name is", name)

7) Input and Output Together


Example
name = input("Enter your name: ")
age = int(input("Enter your age: "))
print("Name:", name)
print("Age:", age)

8) Important Points to Remember


• print() is used for output
• input() is used for input
• input() always takes data as string
• Use int() for whole numbers
• Use float() for decimal numbers

You might also like