- Use the mantra, "Everything in Python has a name, a type and a value"
- Ask students about things in Python according to the Mantra:
- What is the name?
- What is the type?
- What is the value?
- This concept can be difficult.
- Consider the fact that functions are just things that have a name, type, and value.
- Use python tutor to show how things of different types have names, types and values.
- For instance, in the example below there are three different names, types, and values!
- Point out that the variables
functX
,arr
, andnum
are defined in the global space. - The image on the right (containing the Frames and Objects) shows the environment after all of the code has been run.
- Describe this content as what "Python knows."
- Point out that the variables
- Consider the fact that functions are just things that have a name, type, and value.
- Students struggle to pay attention to types (or connect types to Python code at all) because Python is implicitly typed.
- Remind students frequently to think about types in Python.
- Many coding errors result from students not understanding types. When you help students debug their code, ask "what is the type of x?", and as a follow on, "what operations do objects of this type support?"
-
The opinions expressed in the above three points are those of the Suzanne Matthews and not necessarily the position of the Army or DoD