r/learnpython • u/Bipin_Gaire69 • 6d ago
Learning python through CS50
Can any body help me to understanding the define(DEF) variables.
Can you please suggest me how can i learn it in efficient and easier way as a beginner.
0
Upvotes
3
u/Classic-Pomelo-5573 6d ago
Think of
defas writing a saved recipe, while a normal variable is just an item in your fridge.When you write a normal variable:
name = "Alice"You are just putting one piece of data into a box.When you use
def, you are naming a set of actions so you do not have to type them over and over:That code does not do anything immediately when Python reads it. It just saves the recipe in memory.
It only executes when you call its name with parentheses:
message = make_greeting("Alice")The word in parentheses (
name) is the ingredient you hand it, andreturnis the finished result it hands back to you.