0d: 00h: 00m: 00s

🎁 Get 3 extra months of learning — completely FREE

That's 90 extra days to master new skills, build more projects, and land your dream job.

Become a PRO
Background Image

🎁 Get 3 extra months of learning completely FREE

Become a PRO
A
last year
Adeyemicountry asked

What is the difference between variable, comment and string? It's quiet confusing.

Sudip Bhandari
Expert
last year

Hi there! It's perfectly normal to feel confused at the beginning, so let's clarify the differences between a variable, a comment, and a string in Python.

1. Variable: A variable is like a labeled box that holds data in your program. You give it a name to reference the data later on. For example, if you wanted to store someone's age, you might use:

age = 25

In this line, age is the variable name, and it's storing the number 25.

2. Comment: Comments are messages in the code meant for humans to read, not for the computer. They help explain what a part of the code does. Python ignores comments when running the code. You create a comment using the # symbol:

# This is a comment
print("Hello, World!")   # This prints a greeting message

Comments won't affect your code's output; they're just there to help you and others who read your code.

3. String: A string is a sequence of characters (like letters, numbers, and symbols) enclosed in quotes. Strings are like text data. You use either single (' ') or double (" ") quotes to define a string. For example, "Hello, World!" is a string:

greeting = "Hello, World!"

In this example, greeting is a variable storing the string "Hello, World!".

I hope this clears things up for you! Let me know if there's anything else that needs clarification.

Python
This question was asked as part of the Learn Python Basics course.