📚
Dynamic Typing
Dynamic Typing — Variables Can Change
In many programming languages, once you create a variable as a number, it must always be a number. Python is different — it's dynamically typed, which means a variable can hold any type of data, and you can change it at any time:
data = 100 # Right now, data is an integer print(type(data)) # → <class 'int'> data = "hundred" # Now data is a string! print(type(data)) # → <class 'str'> data = 3.14 # Now it's a float! print(type(data)) # → <class 'float'>
Python doesn't complain — it simply changes the label on the box to reflect the new content.
Is This a Good Thing?
It's convenient, but it can also cause bugs. If you accidentally overwrite a number with text, your math will break later. That's why:
- ◆Use descriptive variable names — is less likely to be accidentally reused than
user_agex - ◆Be consistent — if a variable starts as a number, try to keep it as a number
💡💡 Fun fact: This flexibility is one reason Python is so popular for beginners — you don't have to declare types upfront like in Java or C++. But it means you need to be more careful about what your variables contain!
main.pySandbox
main.py
Ctrl + Enter