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

Print Function

Uploaded by

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

Print Function

Uploaded by

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

Print() Function

Definition
English: The print() function is used to display output on the screen.
Roman Urdu: print() function screen par output dikhane ke liye use hota hai.
1. Simple Printing
print("Hello")
Output:
Hello

2. Printing Numbers
print(100)
print(5000)
Output:
100
5000

3. Printing Text and Number


print("Age =",18)
Output:
Age = 18
Explanation: Comma (,) is used to print multiple values.
4. Printing Variables
name = "Ali"
print(name)
Output:
Ali

5. Printing Multiple Variables


name = "Ali"
age = 18

print(name, age)
Output:
Ali 18

6. Printing Labels with Variables


name = "Ali"

print("Name:", name)
Output:
Name: Ali

7. Multiple print() Statements


print("Ali")
print("Karachi")
print("Pakistan")
Output:
Ali
Karachi
Pakistan
Each print() displays output on a new line.
8. One Line Printing
print("Ali", end=" ")
print("Ahmed")
Output:
Ali Ahmed
Explanation: By default, print() moves to a new line. The end parameter keeps the next
output on the same line.
9. Printing with Separator
print("Ali","Ahmed","Sara",sep="-")
Output:
Ali-Ahmed-Sara
print(10,20,30,sep="*")
Output:
10*20*30

10. Escape Characters


New Line (\n)
print("Ali\nAhmed")
Output:
Ali
Ahmed
Tab Space (\t)
print("Ali\tAhmed")
Output:
Ali Ahmed

11. Using Variables Inside Text (f-string)


name = "Ali"

print(f"My name is {name}")


Output:
My name is Ali
This is a modern and professional way to display variables inside text.
12. Printing Calculations
print(10+20)
Output:
30
a = 10
b = 20

print(a+b)
Output:
30

Class Activity
Program 1
print("Python")
Program 2
print("Age =",20)
Program 3
print("Ali","Ahmed",sep="-")
Program 4
print("Ali\nAhmed")
Program 5
a = 10
b = 5

print(a*b)

Important Point
Input → Data Input
Variable → Store Data
Process → Perform Operations on Data
Print → Display Result
print()represents the Output part of a program. This concept is used in almost every
programming language.

You might also like