Variables
Nerd Cafe | نرد کافه
1. What is a Variable?
A variable is like a labeled box that stores data in memory. In ML, variables help us manage:
Data (features, labels)
Hyperparameters (learning rate, epochs)
Results (accuracy, loss)
👉 Think: variable = value
x = 5
name = "Mr Nerd"
price = 19.99
is_active = TrueNotes:
x→ integer (int)name→ string (str)price→ float (float)is_active→ Boolean (bool)Python auto-detects types (no need to declare).
2. Naming Variables (Very Important in ML!)
Python allows flexible names, but ML projects need clarity.
Valid:
Invalid:
Best Practices (PEP8 style):
Use lowercase + underscores →
train_data,test_accuracyBe descriptive →
input_vectorinstead ofivAvoid keywords (
class,def, etc.)
3. Updating Variables
Variables can be updated anytime.
4. Common Data Types in ML
ML Use Cases:
int,float→ parameters (epochs, learning rate)str→ model names, labelslist,tuple→ feature vectorsdict→ configs, hyperparameters
5. Practical Use in ML
6. Multiple Assignments
You can assign multiple values at once:
7. Constants
Python doesn’t enforce constants, but conventionally:
👉 Uppercase = do not change.
8. Type Checking (Debugging in ML)
Helps avoid type errors in training code.
9. Variable Scope
Variables inside functions are local, outside are global.
Output:
10. Dynamic Typing
Python allows changing variable types:
⚠️ Be careful in ML — type mix-ups cause bugs.
11. Variables in NumPy
NumPy is essential in ML.
Output:
12. Summary Table
Basic variable
x = 5
Auto-detects type
Multiple assign
x, y = 1, 2
Split values
Type check
type(x)
Debugging help
Update value
x += 1
Shortcut
Store params
params = {"lr": 0.01}
Common in ML configs
Constants
EPOCHS = 100
Use ALL_CAPS
13. Video Tutorial
💖 Support Our Work
If you find this post helpful and would like to support my work, you can send a donation via TRC-20 (USDT). Your contributions help us keep creating and sharing more valuable content.
TRC-20 Address: TAAVVf9ZxUpbyvTa6Gd5SGPmctBdy4PQwf
Thank you for your generosity! 🙏
Keywords
variables in python, python variable types, declaring variables, variable naming rules, python data types, python for machine learning, python constants, variable scope, python assignment, python beginner guide, python tutorial, python variable examples, variable best practices, python dynamic typing, python debugging, python multiple assignment, machine learning python code, python type checking, python variables cheat sheet, python variable use in ML, nerd cafe , نرد کافه
Channel Overview
🌐 Website: www.nerd-cafe.ir
📺 YouTube: @nerd-cafe
🎥 Aparat: nerd_cafe
📌 Pinterest: nerd_cafe
📱 Telegram: @nerd_cafe
📝 Blog: Nerd Café on Virgool
💻 GitHub: nerd-cafe
Last updated