Python scope of variables

Publié le: 14 juillet 2025
sur la chaîne: The AI channel_63
34
6

Sure! Here's a **simple and clear description of Python variables**:

---

🐍 *Python Variables - Explained*

A *variable* in Python is a name that refers to a value stored in memory. You use variables to store data that your program can use and manipulate.

---

📌 *Key Points:*

1. *No Declaration Needed:*

You don't need to declare the type of variable beforehand.
Example:

```python
x = 5 # integer
name = "Ali" # string
pi = 3.14 # float
```

2. *Dynamic Typing:*

The type of variable can change depending on the value assigned.
Example:

```python
x = 10 # x is an integer
x = "Hello" # now x is a string
```

3. *Variable Naming Rules:*

Must start with a letter or underscore `_`
Can contain letters, digits, and underscores
Case-sensitive (e.g., `age` and `Age` are different)

✅ Valid:

```python
user_name = "Ahmed"
_count = 10
```

❌ Invalid:

```python
1name = "Ali" # starts with a number
user-name = "Zara" # contains a hyphen
```

4. *Assigning Multiple Variables:*

```python
a, b, c = 1, 2, 3
```

5. *Global vs Local Variables:*

**Global**: declared outside functions, accessible everywhere.
**Local**: declared inside functions, only accessible inside them.

---

📘 Example:

```python
name = "Sara" # global variable

def greet():
local_msg = "Hello"
print(local_msg, name) # access global inside function

greet()
```

---

Let me know if you'd like notes in PDF, or examples with input/output!


Sur cette page du site, vous pouvez voir la vidéo en ligne Python scope of variables durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur The AI channel_63 14 juillet 2025, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 34 fois et il a aimé 6 téléspectateurs. Bon visionnage!