Skip to main content

Python Print Statement and Comments Explained with Examples

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
===================================

        

In this project, we used the print() function to create a simple Digital Business Card. This project demonstrates how text can be displayed and formatted in Python. It is a great beginner project for learning output statements and building confidence through practical coding exercises. By modifying the information and design, you can create your own personalized digital business card and improve your Python skills. 🚀💻🤖

●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●



Challenge:
Try answering all the questions by yourself and post your answers in the comments section.

Comments

Popular posts from this blog

Python Variables and Data Types Explained with Examples

🚀 Welcome to NiceinPythonlearn | 📘 Learn Python with Easy Tutorials, Notes & Practice Questions | 💻 Build Real-World Projects | 💬 Enjoying the content?Share your feedback! | 📝 If you have any questions, suggestions, or face any problems, please contact us using the Contact Form or leave a comment. We will do our best to solve it together. 🤝 | ⭐ Follow us for new updates and keep learning! Introduction Variables and Data Types are the fundamental concepts of Python programming. Variables are used to store data, while Data Types define the kind of data a variable can hold. These concepts form the foundation of every Python program, making code simple, organized, efficient, and easy to understand and maintain. Roman English: Variables data store karte hain, aur Data Types batate hain data kis type ka hai. Ye Python programming ki basic foundation hain. Learning Objectives After completing this topic, you will be able to: Underst...

Python input and output (I/O) Statements Explained with Examples

Introduction Python Input and Output are the foundation of interactive programming. Input allows users to enter information, while output displays results on the screen. By learning these concepts, you can create programs that communicate with users, solve real-world problems, and build applications that respond to user input effectively. Hinglish:Python Input aur Output interactive programming ki foundation hai. Input ka use karke user se information li jaati hai, aur Output ka use karke screen par result dikhaya jaata hai. In concepts ko seekhne ke baad aap aise programs bana sakte ho jo users se communicate karein, real-world problems solve karein, aur user ke input ke hisaab se response dene wale applications develop karein. Learning Objectives After completing this lesson, you will be able to: 1.Understand the concept of Input and Output in Python. 2.Use the input() function to take data from users. 3.Use the print() function to display info...