@CodingKurzgeschichten This fits well within the concept of duck-typing which is true for some language but not others.
What matters here is not what it is but how it behaves, and this is a broader mindset in languages such as Python
@CodingKurzgeschichten I wasn't claiming in any way this is unique to Python. The point is that we use range as function – and that's the way it was intended – but it's not. It's a class
@peterdrake @raymondlesley I never said the "behaviour" is different. On the contrary, if you look at my first post, I mention that their behaviour is the same and this is "what matters" in a duck typing language
@peterdrake @raymondlesley conceptually, I believe there is a difference. One creates a new object based on a template, the other normally performs actions with existing objects.
And the capital letter is just a convention, after all. I believe this is deliberate as the intention is that it’s used “like a function”, even though it isn’t. This comes from Python’s duck-typing philosophy.
@andrewhoyer it “behaves” like a function. In many ways, that’s all that matters!
@raymondlesley one could argue the functions are the __new__() and __init__() methods, as with any class, and not the class itself. But the class is callable, like a function, of course
How often have you used the function `range()` in Python? It's often something you use early on as you learn about the `for` loop…
But… did you know it's not really a function, after all?!
Have a look at the docs or use `help()` to check…
`range` is a class. And therefore `range()` creates an instance of the class as is always the case with a class.
So, my question is: "Does it matter?"
Technically, it does. A function is not a class – they're different things
But in practice, what matters is how it behaves and not what it is!
This is a key principle in Python when thinking about data types. What they do and how they behave matters more that what they are!
So you can use `range()` like a function, even though it's not!
When you learn to code, in Python or other languages,, you start by learning about the tools you’ll need and the rules for each one of those tools. You learn the syntax of the for loop and what it does, for example. With time, you also learn when to use this tool and when not to use it.
What’s more challenging in the early and not-so-early days when you learn Python coding is to join the dots between the various topics you learn and to view them as a coherent set of tools all working together.
Making the transition from knowing how to use lots of separate programming tools to seeing those tools as aspects of the same story is one of the rites of passage to move from beginner to intermediate, whichever way you define beginner and intermediate.
What has helped me get this type of understanding is good analogies. Here’s the one that works for me:
#Python #Programming #Coding #LearnPython #LearnToCode
https://thepythoncodingbook.com/2021/08/12/learn-python-coding-with-monty-and-the-white-room/
Just started reading this bad boy! Turns out there are tons of stuff I didn’t know about #pytest .
Great job @brianokken.
I wrote some #python code today to integrate Mastodon into my stream deck. Now we can announce new @talkpython and @pythonbytes episode in the click of a button, see image.
You've possible heard the quote which says that "Debugging is like being the detective in a crime movie where you are also the murderer”
A while ago, I decided to take this quote a bit more literally, but no, not "fully literally" (if you know what I mean - I didn't commit any crimes, just to be clear!)
Don't take this article too seriously, though!
–> Debugging Python Code Is Like Detective Work — Let’s Investigate
#Python #coding #programming #debugging #LearnPython #learntocode
@brandonb_phy I think the intuitive understanding of such relations is not often fully appreciated by students (and maybe teachers) at secondary/high school
@freemo @ambv it seems like some can choose (possibly inadvertently) to silo themselves a lot more than others based on choice of servers. Those who silo themselves a lot will of course, by definition, have a skewed sense of what goes on. I’ve not been here long enough to know which servers are which with clarity, but I’m pleased I switched to qoto early on
@hynek no, I can see the asterisk as plain text
@hynek if I use plain text mode the symbols stay there but they’re rendered plain text for everyone. If I switch to markdown mode (a feature on qoto), then qoto users see it properly rendered but others see plain text with the markdown symbols stripped out
@hynek so for the toot above, I wrote using back ticks and ** but I suspect you saw neither
@hynek And that's the issue, different people see different things.
Same with markdown, for example this below is a code block that some servers will see properly rendered, but you're likely to see just plain text
`print("This is a code block")`
**and this is in bold here**
• 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!