In my on ramp to Python, for beginners, I find harping on "types" a great intro (if unoriginal -- a lot of us do it).
For one thing, we can hold fixed to the "type" idea while changing the source of the type from built-in, to standard library module, to 3rd party -- three tiers in my "dimensions of Python". These dimensions are (again): * keywords and core syntax (punctuation symbols e.g. [ ] ( ) : etc.) * built-ins * __ribs__ (special names e.g. __getitem__) * standard library * 3rd party (or cloud, or ecosystem, most of what you write yourself) What I say about OO and types is: this was an attempt to mirror your natural language thinking in terms of things having type and thereby characteristics. Computer languages were reaching out to meet us half way, in our native context. "Easy to reason about" in proportion to one's having a strong sense of metaphor perhaps. Not self-proving. The datetime type is, like the string, great for escaping the vortex of "number types only" (where high school math teachers seem to wish to confine themselves for some reason, although this is not a limitation of maths). Many newcomers to programming expect incessant number crunching and languages that only care about numeric methods. That's a stereotype to smash early. Some types help us do that. I have a "permutation" type that's like a number in being very mathy, supports __mul__ and __invert__, but it's not a "number" type. https://repl.it/@kurner/Permutations (repl.it worth checking out if you haven't) datetime also persuades us to appreciate that others have dealt with the complexity. We get the fruits of their efforts. Calendar stuff is sooo... tedious? Not forgetting timezones and daylight savings time. It's a lot of useful machinery that used to stay locked away in temples. A good example of a 3rd party type? Actually there's a lot of 3rd party datetime stuff. Lets get back to number crunching why not? gmpy2 - Extended Precision Decimals. Very like decimals in Standard Library, which is great, for comparing and contrasting similar types. A strong focus on types right from the get go then helps explain the power of Python's 'class' keyword: Python lets you extend the type system with types of your own. That's the OO model after all (not at all unique to Python), and meant to mirror reality in some ways, a different goal then being "easy to reason about" (which is a holy grail as well -- it's not either/or). Example using of gmpy2 in a "learning Python" curriculum context: https://nbviewer.jupyter.org/github/4dsolutions/Python5/blob/master/S_Train.ipynb (more links from the bottom if wanting more of the same) The feature I want to emphasize is the results of decimal calculations mostly look like this: JB Icosa: 18.512295868219161196009899292654531923571426913640152615969 JB Cubocta: 20.000000000000000000000000000000000000000000000000000000000 SuperRT: 21.213203435596425732025330863145471178545078130654221097650 Not what you'd be seeing with a calculator (too precise). Not floating point numbers, clearly, in the sense of IEEE 754. I find extended precision types useful for inspiring students to developing that special and useful skill, of going from conventional sigma notation, to working programs using loops -- what sigmas stand for. Ramanujan had some doozies converging to Pi (or 1/Pi) or whatever. We've looked at those before on edu-sig. Example: https://github.com/4dsolutions/Python5/blob/master/Extended%20Precision.ipynb Kirby
_______________________________________________ Edu-sig mailing list Edu-sig@python.org https://mail.python.org/mailman/listinfo/edu-sig