-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconcept-functions-explained-cards.json
More file actions
70 lines (70 loc) · 4 KB
/
concept-functions-explained-cards.json
File metadata and controls
70 lines (70 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
{
"deck": "Concept — Functions Explained",
"description": "Defining functions, parameters, return values, default arguments, scope",
"cards": [
{
"id": "c-func-01",
"front": "How do you define and call a function in Python?",
"back": "Use def to define, then call by name with parentheses.\n\ndef greet(name):\n return f\"Hello, {name}!\"\n\nmessage = greet(\"Alice\") # \"Hello, Alice!\"\n\ndef = define, name = the function name, (name) = parameter, return = send back a value.",
"concept_ref": "concepts/functions-explained.md",
"difficulty": 1,
"tags": ["functions", "def"]
},
{
"id": "c-func-02",
"front": "What happens if a function has no return statement?",
"back": "It returns None automatically.\n\ndef say_hello():\n print(\"Hello!\")\n\nresult = say_hello() # prints \"Hello!\"\nprint(result) # None\n\nFunctions that do something (print, write) often return None.\nFunctions that compute something should return the result.",
"concept_ref": "concepts/functions-explained.md",
"difficulty": 2,
"tags": ["return", "None"]
},
{
"id": "c-func-03",
"front": "What is the difference between a parameter and an argument?",
"back": "Parameters are the names in the function definition.\nArguments are the values you pass when calling.\n\ndef add(a, b): # a, b are parameters\n return a + b\n\nadd(3, 5) # 3, 5 are arguments",
"concept_ref": "concepts/functions-explained.md",
"difficulty": 1,
"tags": ["parameters", "arguments"]
},
{
"id": "c-func-04",
"front": "How do default parameter values work?",
"back": "Set a default with = in the definition. Optional when calling.\n\ndef greet(name, greeting=\"Hello\"):\n return f\"{greeting}, {name}!\"\n\ngreet(\"Alice\") # \"Hello, Alice!\"\ngreet(\"Alice\", \"Hey\") # \"Hey, Alice!\"\n\nParameters with defaults must come after parameters without.",
"concept_ref": "concepts/functions-explained.md",
"difficulty": 2,
"tags": ["defaults", "parameters"]
},
{
"id": "c-func-05",
"front": "What happens if you call a function without parentheses?",
"back": "You get the function object itself, not its return value.\n\ngreet # <function greet at 0x...> (the function object)\ngreet(\"Alice\") # \"Hello, Alice!\" (calls the function)\n\nThis is a common mistake — always include () to call.",
"concept_ref": "concepts/functions-explained.md",
"difficulty": 2,
"tags": ["functions", "calling"]
},
{
"id": "c-func-06",
"front": "Why do functions matter? Name 4 reasons.",
"back": "1. Reuse — write once, use everywhere\n2. Organize — break problems into named pieces\n3. Test — test each piece independently\n4. Read — calculate_tax(price) is clearer than 5 lines of math\n\nFunctions are the building blocks of all programs.",
"concept_ref": "concepts/functions-explained.md",
"difficulty": 1,
"tags": ["functions", "principles"]
},
{
"id": "c-func-07",
"front": "What error do you get if you define a function after calling it?",
"back": "NameError — the function does not exist yet.\n\ngreet(\"Alice\") # NameError: name 'greet' is not defined\n\ndef greet(name):\n return f\"Hello, {name}!\"\n\nPython reads top-to-bottom. Define functions before using them.",
"concept_ref": "concepts/functions-explained.md",
"difficulty": 2,
"tags": ["functions", "errors"]
},
{
"id": "c-func-08",
"front": "What is the common mistake with forgetting return?",
"back": "The function runs but gives None instead of the result.\n\ndef add(a, b):\n result = a + b\n # Forgot: return result\n\ntotal = add(3, 5) # total is None, not 8\n\nAlways check: does my function return the value, or just compute it?",
"concept_ref": "concepts/functions-explained.md",
"difficulty": 2,
"tags": ["return", "mistakes"]
}
]
}