Skip to content

Commit

Permalink
error
Browse files Browse the repository at this point in the history
  • Loading branch information
maglovskiNenad committed Nov 11, 2024
1 parent 6fae741 commit 2af3c32
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions _posts/2024-11-10-python.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Python is a high-level, interpreted programming language known for its readabili

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

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

1. Examples of valid variable names:
```Python


```python
first_name = "Alice"
_age = 30
height_in_cm = 175

```

2. Examples of invalid variable names:
```Python

```python
2nd_variable = "invalid" # Starts with a number
first-name = "invalid" # Contains a hyphen
```
Expand All @@ -54,7 +56,7 @@ first-name = "invalid" # Contains a hyphen
- Tuples (tuple): Ordered, immutable collection of items (e.g., (1, 2, 3))
- Dictionaries (dict): Key-value pairs (e.g., {"name": "Alice", "age": 25})

```Python
```python
x = 42
print(type(x)) # Output: <class 'int'>

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

### Reassigning Variables

```Python
```python
number = 10
print(number) # Output: 10

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

number = "ten" # Reassign with a string value
print(number) # Output: ten

```

### Constants

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:

```Python
```python
PI = 3.14159
GRAVITY = 9.8
```

### Multiple Variable Assignment

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

```Python
```python
global_var = "I am global"

def my_function():
Expand Down

0 comments on commit 2af3c32

Please sign in to comment.