1) Print Statement Function in Python
A print statement Function is used to show output on the screen. In Python, we write print() with a small letter p, not a capital letter.
Roman : Print statement Function screen par output dikhane ke liye use hota hai. Python me print() small letter p se likhte hain, kyunki Python case-sensitive hota hai.Example of Print Statement Function in Python :
print("Hello World")
Output(show on Terminal):
Hello World
Another Example of Print Statement Function in Python :
print(10)
print(2.0)
print(True)
print(10+5)
print(2*5)
print(0-0)
Output(show on Terminal):
10
2.0
True
15
10
0
2) Comments in Python (Single and Multiples):
Single Line Comments using Hash(#) in Python
A comment is used to explain a line of code. In Python, a comment is written using #(hash) at the start of the line, and the shortcut key Ctrl + / can be used to add or remove comments,but comment doesn't show in output
Roman : Comment line ko explain karne ke liye use hota hai. Python me comment # se line ke start me likha jata hai, aur shortcut key Ctrl + / se bhi comment add ya remove kiya ja sakta hai, lekin output mein comment nhi show hota hai.Example of single Line Comments in Python :
# It is a print Statement -- using Comments is Single Line Comments
print("My Name is Hamid Hasnain")
Output(show on Terminal):
My Name is Hamid Hasnain
Multiple Line Comments using (''' ''') or (""" """) in Python
A multiple line comment is used when we need to write long explanations or comments in multiple lines. In Python, it is commonly written using triple quotes (''' ''' or """ """). Using # is mainly for single line comments.
Roman: Multiple line comment tab use hota hai jab hume long explanation ya multiple lines me comment likhna hota hai. Python me isko commonly triple quotes se likhte hai (''' ''' ya """ """). ka use mainly single line comment ke liye hota hai.Example of Multiple Line Comments in Python :
# print a Two Line Code for Jokes of Code! --- it is a Single line Comments using Hash #
'''Programmer: Why is my code not working?
Also Programmer: I didn’t even run the code ---- It is a Multiple Line Comments using triple quotes (""" or ''')'''
print('''Programmer: Why is my code not working?
Also Programmer: I didn’t even run the code''')
Output(show on Terminal):
Programmer: Why is my code not working?
Also Programmer: I didn’t even run the code
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
🐞 Code Errors (Debug) and Solutions:
| Code | Correct / Incorrect | Reason | Output |
|---|---|---|---|
| Print("Hello") | ❌ Incorrect | Python is case-sensitive. Use print(), not Print(). |
NameError |
| print(Hello) | ❌ Incorrect | Hello is not enclosed in quotes, so Python treats it as a variable. | NameError |
| print("Hello") | ✅ Correct | Text is inside quotes and the function name is correct. |
Hello |
| print("Hello") | ❌ Incorrect* | Extra indentation at the start may cause an IndentationError if not inside a code block. |
IndentationError |
Note
Python is case-sensitive. Always use print() in lowercase.
Strings must be enclosed in quotation marks (" " or ' ').
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
✔️Try These Small Python Exercises to Build Confidence 😎🏆
1. What will be the output of the following code?
Python
print("Hello")
2. Print the result of 2 + 5. What output do you get?
Python
print(2 + 5)
3. Use the print() statement to display your:
Name
Age
Phone Number
Example:
Python
print("Name: John")
print("Age: 20")
print("Phone: 1234567890")
4. What will be the output of the following code?
Python
print(2.0)
Also, what type of number is 2.0 called in Python?
5. What is the purpose of the # symbol in Python?
Example:
Python
# This is a comment
print("Hello")
What kind of comment is this?
6. How can you write multi-line comments in Python?
Example:
Python
"""
This is a multi-line comment.
It can span multiple lines.
"""
or
Python
'''
This is also a multi-line comment.
'''
When should you use multi-line comments?
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
🏗 Learn Concepts and Build Project:
In this beginner-friendly Python project, we will create a simple Digital Business Card using the print() function. The business card will display important information such as your name, phone number, email address, company name, and profession in a well-organized format. This project helps you understand how the print() function works in Python while building something practical and useful. Creating small projects like this makes learning more enjoyable, improves your coding confidence, and helps you apply programming concepts in real-world examples. 🚀💻
Source Code:
print("===================================")
print(" DIGITAL BUSINESS CARD ")
print("===================================")
print("Name : Hamid Hasnain")
print("Profession: Engineering Student")
print("Company : Future Tech Solutions")
print("Phone : +91 9876543210")
print("Email : hamid@example.com")
print("Website : www.example.com")
print("===================================
Output(show on Terminal):
===================================
DIGITAL BUSINESS CARD
===================================
Name : Hamid Hasnain
Profession: Engineering Student
Company : Future Tech Solutions
Phone : +91 9876543210
Email : hamid@example.com
Website : www.example.com
===================================
Comments
Post a Comment