You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Day 1/notes and codes.md
+54-9Lines changed: 54 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,11 +13,12 @@
13
13
|--|--|--|
14
14
|1|Intro to python|[Click Here](#intro-to-python)|
15
15
|2|Defining a variable|[Click Here](#defining-a-variable)|
16
-
|3|Data Types in Python|[Click Here](#data-types-in-python)|
17
-
|3-1|String Data Type|[Click Here](#3-1-string-data-type)|
18
-
|3-2|Numeric Data Type|[Click Here](#3-2-numeric-data-type)|
19
-
|3-3|Boolean & None Data Type|[Click Here](#3-3-boolean-and-none-data-type)|
20
-
|3-4|Collection Data Type|[Click Here](#3-4-collection-data-type)|
16
+
|3|Rules for Defining Variables in Python|[Click Here](#rules-for-defining-variables-in-python)|
17
+
|4|Data Types in Python|[Click Here](#data-types-in-python)|
18
+
|4-1|String Data Type|[Click Here](#4-1-string-data-type)|
19
+
|4-2|Numeric Data Type|[Click Here](#4-2-numeric-data-type)|
20
+
|4-3|Boolean & None Data Type|[Click Here](#4-3-boolean-and-none-data-type)|
21
+
|4-4|Collection Data Type|[Click Here](#4-4-collection-data-type)|
21
22
22
23
23
24
## Intro to Python
@@ -72,6 +73,50 @@ Try experimenting with different variable names and values to solidify your unde
72
73
73
74
**[🔝Index](#index)**
74
75
76
+
---
77
+
78
+
## Rules for Defining Variables in Python
79
+
80
+
When defining variables in Python, there are a few rules and guidelines to follow to ensure your code runs correctly and is easy to read. Let’s take a look at these essential rules:
81
+
82
+
**1. Variable names must begin with a letter or an underscore (_).**
83
+
- Valid: `x`, `_my_variable`, `age`
84
+
- Invalid: `1age`, `@variable`
85
+
86
+
**2. Variable names can only contain letters (a-z, A-Z), numbers (0-9), and underscores (_).**
87
+
- Valid: `my_var`, `age_123`, `my_variable`
88
+
- Invalid: `my-variable`, `my variable`
89
+
90
+
**3. Variable names are case-sensitive.**
91
+
-`age`, `Age`, and `AGE` are considered different variables in Python.
92
+
93
+
**4. Avoid using Python keywords as variable names.**
94
+
- Keywords are reserved words in Python, and they have special meanings. You can’t use them as variable names. Examples of keywords include: `if`, `else`, `for`, `while`, `def`, `class`, etc.
95
+
- Valid: `variable`, `my_var`
96
+
- Invalid: `if`, `else`, `while`
97
+
98
+
**5. Variable names should be descriptive and follow a consistent naming convention.**
99
+
- Use **snake_case** for variable names (e.g., `user_age`, `total_price`).
100
+
- Avoid one-letter variables unless in specific cases (e.g., `x`, `y` in mathematical operations).
101
+
102
+
**6. You can reassign variables to different data types.**
103
+
- Since Python is dynamically typed, you can change the type of a variable during the execution of a program.
104
+
- Example:
105
+
```python
106
+
x =10# x is an integer
107
+
x ="Hello"# x is now a string
108
+
```
109
+
110
+
**7. Whitespace (spaces, tabs) isnot allowed within variable names.**
111
+
- Valid: `first_name`, `total_score`
112
+
- Invalid: `first name`, `total score`
113
+
114
+
**8. Variables cannot start with a number.**
115
+
- Valid: `age1`, `score_100`
116
+
- Invalid: `1age`, `100_score`
117
+
118
+
**[🔝Index](#index)**
119
+
75
120
---
76
121
## Data Types in Python
77
122
@@ -87,7 +132,7 @@ Each type has unique properties and methods, and Python automatically manages me
87
132
88
133
**[🔝Index](#index)**
89
134
90
-
### 3-1 String Data Type
135
+
### 4-1 String Data Type
91
136
92
137
Strings (`str`) in Python represent sequences of Unicode characters. Strings are **immutable**, meaning once created, they cannot be changed directly.
Python provides several built-in collection data types that group multiple values into a single variable. These collections are versatile and widely used to store, organize, and manipulate data.
0 commit comments