RT @PythonMorsels@twitter.com
We have immutable objects in Python but we don't have constant variables.
The UPPERCASE_CONVENTION for constants is just a naming convention in #Python. It doesn't stop variables from being re-assigned.
https://pym.dev/python-doesnt-have-constants/
🐦🔗: https://twitter.com/PythonMorsels/status/1534161787737759744
# Want to learn Python?
There must be many here looking to #LearnToCode and to #LearnPython
Happy to connect and help answer questions anyone might have
_ask away…_
@trinsec As for making only the first one listed, I've experimented with this on one thread and I'll do it one ones I write directly here. But others come from an existing workflow and are posted automatically, so until there's a setting to make this default on all threads (that would be a great setting to have!), it may be tricky
@trinsec Separating into separate posts makes them more bite-sized and more digestible. I don't think I like the idea of long posts, personally, although I can see rare instances where that may be useful
Although the early parts of the series are not on here, you can see them on my Typefully page: https://typefully.com/s_gruppetta_ct
• Using keyword-only arguments, or the "rogue" asterisk * in function signatures
Next up:
• type hinting
• general best-practices when defining and using functions
• Choosing to use arguments as either positional or keyword
• Using optional arguments by assigning default values
• *args and **kwargs, or variable number of positional and keyword arguments
• Using positional-only arguments, or the "rogue" forward slash / in functions
• …
For those who've been following the #Python Functions Series, today we'll take a short break and Day 10 will return tomorrow – There's still a related-thread later today, but not directly part of the series.
So far we've covered:
• terminology (boring but useful)
• …
@trinsec Sorry, only newlines not preserved
@trinsec But what you're doing there, I think, is first a pair of backticks with nothin in, then another pair with Test, and then another empty pair
if you try to put a block of code, newlines and whitespace is not preserved
```
This is first line
This is second line
And this is an indented line
```
Addendum (some sad news): Since taking those pictures for the article, that sole remaining espresso cup has suffered this fate
I was told I can't say Rest In Pieces
Instead, you should put a coffee cup in the machine when you turn it on:
`>>> cup = make_coffee(`
`... electricity,`
`... water,`
`... my_favourite_blend,`
`... )`
Now, you no longer make a mess on the kitchen bench you're collecting what's returned into something
There's a fuller version of this analogy here, too:
https://thepythoncodingbook.com/2022/09/14/functions-in-python-are-like-coffee-machines/
8/
You called the function like this:
`>>> make_coffee(`
`... electricity,`
`... water,`
`... my_favourite_blend,`
`... )`
and therefore, the coffee _returned_ is not collected and stored in anything…
7/
The coffee flows directly into the drainage tray at the bottom of the machine and will likely overflow, making a mess on your kitchen bench…
6/
— 4 —
When the coffee machine does its thing, hot, liquid coffee will emerge from the machine.
You could say the coffee machine _returns_ liquid coffee.
but, there's one problem…
5/
— 3 —
When you call the function/press the "On" button on the coffee machine, the machine will "do stuff" inside.
If you just care about drinking your coffee, you don't care what's happening inside the machine…
If you're an engineer building your own coffee machine, or you want to open up your coffee machine to fix it or—ahem—make improvements, then you _do_ care about what's happening inside the coffee machine.
4/
— 2 —
You press the "On" button—this is equivalent to calling the function.
You can almost see the similarity between the typical "On" button and the parentheses ( ) used to call a function in Python!
3/
A function is like a coffee machine
– 1 –
It needs inputs to work (arguments):
— water
— electricity
— ground coffee beans (or pods if so inclined)
You can choose to put different blends of coffee into your machine (choice of what argument to pass to function)
2/
• Rethinking how to teach programming – I prefer the friendly, relaxed approach when communicating about Python programming
• I write about Python on The Python Coding Book blog and on Real Python
• Former Physicist
• Expect posts on scientific and numerical programming –> NumPy, Matplotlib and friends!