Skip to content

Commit 2943014

Browse files
Update README.md
1 parent 1177fe5 commit 2943014

File tree

1 file changed

+174
-24
lines changed

1 file changed

+174
-24
lines changed

week_1/README.md

Lines changed: 174 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,188 @@
1-
# Python Comments and Variables
1+
# 🐍 Python Comments and Variables - For Complete Beginners
22

3-
This project provides a basic introduction to comments and variables in Python, illustrating how they are used to write clear and maintainable code.
3+
Welcome to the world of programming! This guide is specially designed for **new students** who are just starting their journey in Python.
44

5-
## Table of Contents
5+
---
66

7-
- [Overview](#overview)
8-
- [Comments](#comments)
9-
- [Single-line Comments](#single-line-comments)
10-
- [Multi-line Comments](#multi-line-comments)
11-
- [Variables](#variables)
12-
- [Variable Naming Rules](#variable-naming-rules)
13-
- [Examples of Variables](#examples-of-variables)
14-
- [Example Code](#example-code)
15-
- [Getting Started](#getting-started)
16-
- [Contributing](#contributing)
17-
- [License](#license)
7+
## 📘 Table of Contents
188

19-
## Overview
9+
- [Why Learn Comments and Variables?](#why-learn-comments-and-variables)
10+
- [What is a Comment?](#what-is-a-comment)
11+
- [Real-life Example of a Comment](#real-life-example-of-a-comment)
12+
- [Types of Comments](#types-of-comments)
13+
- [What is a Variable?](#what-is-a-variable)
14+
- [Real-life Example of a Variable](#real-life-example-of-a-variable)
15+
- [Variable Naming Rules](#variable-naming-rules)
16+
- [Why Are They Important?](#why-are-they-important)
17+
- [Can We Write Code Without Comments and Variables?](#can-we-write-code-without-comments-and-variables)
18+
- [Practice Questions](#practice-questions)
19+
- [Resources for Further Learning](#resources-for-further-learning)
2020

21-
Understanding how to use comments and variables is essential for writing effective Python programs. Comments help explain the code, while variables are used to store data.
21+
---
2222

23-
## Comments
23+
## ❓ Why Learn Comments and Variables?
2424

25-
### Single-line Comments
25+
Before writing big or small programs, you must learn **how to explain your code (comments)** and **how to store data (variables)**.
2626

27-
Single-line comments start with a `#` and extend to the end of the line. They are used to provide brief explanations or notes within the code.
27+
They make your code:
2828

29-
## Practice Questions and Resources
29+
✅ Easy to understand\
30+
✅ Easy to update\
31+
✅ Easy to share with others
3032

31-
- **Practice Questions**: [HackerRank Python Practice](https://www.hackerrank.com/domains/tutorials/10-days-of-python)
32-
- **YouTube Channel**: [My Python Playlist](https://www.youtube.com/playlist?list=PLX1eV90xXed2wujMJKUdsWQu2UMS9ROGO)
33+
---
3334

34-
Explore these resources to test your knowledge and enhance your programming skills!
35+
## 🛈 What is a Comment?
36+
37+
A comment is a **line that Python ignores** while running the program. It is just for **humans to read**.
38+
39+
You write a comment to explain **what your code is doing** so that **you or someone else can understand it later**.
40+
41+
### 🧠 Syntax:
42+
43+
```python
44+
# This is a comment
45+
```
46+
47+
---
48+
49+
## 👨‍🏫 Real-life Example of a Comment
50+
51+
Just like we write notes in textbooks to understand something better, we write **comments** in code to explain it.
52+
53+
📘 Example:
54+
55+
```python
56+
# Store the name of the user
57+
name = "Fahad"
58+
```
59+
60+
🖼️ *Image Idea*:\
61+
![Image Idea](https://th.bing.com/th/id/OIP.W09inty_0PppHzN8yIeB2AHaEW?rs=1&pid=ImgDetMain)
62+
63+
---
64+
65+
## ✍️ Types of Comments
66+
67+
### ✅ Single-line Comment
3568

3669
```python
3770
# This is a single-line comment
38-
print("Hello, World!") # This comment explains the print function
71+
print("Hello World")
72+
```
73+
74+
### ✅ Multi-line Comment
75+
76+
```python
77+
'''
78+
This is a multi-line comment.
79+
Used to explain big blocks of code.
80+
'''
81+
print("Welcome!")
82+
```
83+
84+
---
85+
86+
## 🧮 What is a Variable?
87+
88+
A variable in Python is like a container that stores data. You use it to **save values** like numbers, text, or anything else in your program.
89+
90+
💡 Think of it like giving a label to a value so you can use it again and again.
91+
92+
### 🧠 Syntax:
93+
94+
```python
95+
variable_name = value
96+
```
97+
98+
📘 Example:
99+
100+
```python
101+
age = 22
102+
city = "Karachi"
103+
```
104+
105+
---
106+
107+
## 📆 Real-life Example of a Variable
108+
109+
Imagine you have a **lunchbox**. You can name it `my_lunchbox` and put a sandwich inside.
110+
111+
In code:
112+
113+
```python
114+
my_lunchbox = "Sandwich"
115+
```
116+
117+
Now whenever you say `my_lunchbox`, Python knows you mean "Sandwich".
118+
119+
![Image Idea](https://th.bing.com/th/id/R.162ef8c841f8d573ca1611a76d0ad3ba?rik=kS30KGK9m5UVUA&pid=ImgRaw&r=0&sres=1&sresct=1)
120+
121+
Lunchbox with label = Variable with name
122+
123+
---
124+
125+
## 📏 Variable Naming Rules
126+
127+
When creating variable names in Python, follow these rules:
128+
129+
1. ✅ Use letters (a-z, A-Z), numbers (0-9), and underscores (_)
130+
2. ❌ Do NOT start with a number
131+
3. ❌ No spaces allowed (use underscores instead)
132+
4. ❌ Avoid special characters like !, @, #, etc.
133+
5. ✅ Use meaningful names (e.g., `user_name` instead of `x`)
134+
135+
📘 Examples:
136+
```python
137+
user_name = "Ali" # Valid
138+
age1 = 25 # Valid
139+
1age = 25 # ❌ Invalid (starts with a number)
140+
user name = "Sara" # ❌ Invalid (contains space)
141+
```
142+
143+
---
144+
145+
## 💡 Why Are They Important?
146+
147+
| Feature | Comment | Variable |
148+
| ------------------------- | ------- | -------- |
149+
| Helps you understand code | ✅ Yes | ❌ No |
150+
| Stores data for you | ❌ No | ✅ Yes |
151+
| Makes code easier to read | ✅ Yes | ✅ Yes |
152+
| Helps in teamwork | ✅ Yes | ✅ Yes |
153+
154+
---
155+
156+
## 🚫 Can We Write Code Without Comments and Variables?
157+
158+
Technically, **yes** you can write simple code without them...
159+
160+
But it's like:
161+
162+
- Writing a story **without headings or notes** (no comments)
163+
- Or remembering all data **without saving it** (no variables)
164+
165+
✅ It's better to **always use** them to write clean and professional code.
166+
167+
---
168+
169+
## 🧪 Practice Questions
170+
171+
1. Write a single-line comment that says: "This code prints a message"
172+
2. Create a variable called `fruit` and store `"Apple"` in it
173+
3. Create three variables: `name`, `age`, and `city` with your own info
174+
4. Write a multi-line comment explaining what your code does
175+
5. Can you write a simple program that uses comments and variables together?
176+
177+
---
178+
179+
## 🔗 Resources for Further Learning
180+
181+
- 📝 [HackerRank Python Practice](https://www.hackerrank.com/domains/tutorials/10-days-of-python)
182+
- 🎥 [My Python Playlist on YouTube](https://www.youtube.com/playlist?list=PLX1eV90xXed2wujMJKUdsWQu2UMS9ROGO)
183+
184+
---
185+
186+
Made By Fahad Bin Ashfaq for beginner Python learners.\
187+
Happy Coding! 🚀
188+

0 commit comments

Comments
 (0)