Skip to content

Commit 2af3c32

Browse files
error
1 parent 6fae741 commit 2af3c32

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

_posts/2024-11-10-python.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Python is a high-level, interpreted programming language known for its readabili
1414

1515
In Python, declaring a variable is as simple as assigning a value to a name using the = operator:
1616

17-
```Python
17+
```python
1818
# Examples of variables
1919
name = "Alice" # string variable
2020
age = 25 # integer variable
@@ -31,15 +31,17 @@ is_student = True # boolean variable
3131
- Variable names are case-sensitive (age and Age would be two different variables).
3232

3333
1. Examples of valid variable names:
34-
```Python
34+
35+
36+
```python
3537
first_name = "Alice"
3638
_age = 30
3739
height_in_cm = 175
38-
3940
```
4041

4142
2. Examples of invalid variable names:
42-
```Python
43+
44+
```python
4345
2nd_variable = "invalid" # Starts with a number
4446
first-name = "invalid" # Contains a hyphen
4547
```
@@ -54,7 +56,7 @@ first-name = "invalid" # Contains a hyphen
5456
- Tuples (tuple): Ordered, immutable collection of items (e.g., (1, 2, 3))
5557
- Dictionaries (dict): Key-value pairs (e.g., {"name": "Alice", "age": 25})
5658

57-
```Python
59+
```python
5860
x = 42
5961
print(type(x)) # Output: <class 'int'>
6062

@@ -67,7 +69,7 @@ print(type(z)) # Output: <class 'str'>
6769

6870
### Reassigning Variables
6971

70-
```Python
72+
```python
7173
number = 10
7274
print(number) # Output: 10
7375

@@ -76,21 +78,20 @@ print(number) # Output: 15
7678

7779
number = "ten" # Reassign with a string value
7880
print(number) # Output: ten
79-
8081
```
8182

8283
### Constants
8384

8485
Although Python does not have a built-in way to declare constants (variables that should not change), it’s a common convention to use all-uppercase names for variables intended to be constant:
8586

86-
```Python
87+
```python
8788
PI = 3.14159
8889
GRAVITY = 9.8
8990
```
9091

9192
### Multiple Variable Assignment
9293

93-
```Python
94+
```python
9495
a, b, c = 1, 2, 3
9596
print(a) # Output: 1
9697
print(b) # Output: 2
@@ -104,7 +105,7 @@ print(x, y, z) # Output: 100 100 100
104105
- Global Variables: Defined outside of a function and can be accessed anywhere in the code.
105106
- Local Variables: Defined inside a function and can only be accessed within that function.
106107

107-
```Python
108+
```python
108109
global_var = "I am global"
109110

110111
def my_function():

0 commit comments

Comments
 (0)