Python Print() and Beyond
josiasdev.bestThe official docs say the same thing in fewer words:
https://docs.python.org/3/library/functions.html#print
I definitely recommend the official Python docs. They are well written, and you'll find lots of useful nuggets like this.
I personally wish the official docs got a much heavier weighting in the search engines. I hate receiving crap from w3schools and dev.to over the actual good stuff. Stupid SEO crap, but it's a resume puff piece. I can't blame them for writing it.
It is a good article with some good examples, I just wish these kinds of articles didn't exist.
Don’t forget Tutorialspoint, which in my experience is way more endemic to Python PSL search results than every other SEO crap site. And unlike w3schools, it’s not even useful for a quick glance.
On rare occasions they'll rank for a concept that I need, but don't know exists. Things like the SAX pattern for XML. Which is somewhat useful.
If you already know what you want you can simply add "docs.python.org". It's more work but it's worth it.
This is not about you, or me, but about general public. When they search for something on general purpose search engines, the docs.python.org should rank higher, so they too can get quality information.
Why should I "you can simply" instead of search engine itself?
Dude, I was just providing a practical solution to an actual problem it seems to bother the GP.
You (we) have little control of how search engine works, so you can keep saying whatever you like, aren't' going to do a dang thing.
> You (we) have little control of how search engine works
Complaining on HN can sometimes work miracles.
Yes, but this article explained it in a more interesting way which makes it easier to remember.
> By default, all the values you pass to it are separated by empty strings
I think it's space, not empty string?
------
Another error:
If we execute that, we notice the text is no more separated by a new line. Let's try that again! But this time, we want it to end by y and move to a new line.
print("Hello James", end="y\n")
print("How are you doing", end="\n")
We get the following output
Hello Jamesy
How are you doingy
Yay it worked !
But your second line in code uses `end="\n"`. It won't print "doingy".I really don't see any value in these sort of half-baked posts full of inaccuracies that contribute to low SNR.
Someone mentioned that it's a resume puff piece, but to me, it does more harm to the person that wrote it than good. It exposes his superficial level of understanding and lack of deep programming knowledge.
Would you hire him based on this? I wouldn't.
To end on a positive note, some advice to the author:
Programming is a field where you can't really hide your skill from people that are better than you. This means that "fake it till you make it" isn't a viable strategy. Embrace precision in your writing and avoid guesswork. If you're guessing about behavior, state so (or better, do research so that you don't have to guess). Ideally, you produce technical posts that go deep, have something to say (about the problem at hand or yourself) and are not mere regurgitations of surface-level knowledge. If you don't have something interesting to say, say nothing.
> Programming is a field where you can't really hide your skill from people that are better than you.
You're not wrong, but one rarely needs to impress a person better than me to get a job. Hiring managers are rarely subject-matter experts.
Unless only possible job, I highly recommend not wasting your time at company that doesn’t have your future coworkers doing interviews and having hiring input.
That company will likely not have good developers, will be an engineering shit show, and worst of all you will have little opportunity to learn or gain good experience.
You're assuming the worst intentions by OP there and attacking them. Please do write a better piece if you'd like. Write a critique even, but all you're doing right now is saying it's bad without showing how.
OP liked something well enough to write a post on it and shared it. I thought the writing was insightful and intriguing. Sure, the official docs contain the same information but I've read that tiny snippet and never retained that information. This way I'll be able to remember this for a longer time.
Since you're saying this post has inaccuracies, rather than being smug about your superior knowledge, why not point out what they are?
Also there's nothing wrong with writing a simple post in your blog. The internet isn't going to get full.
Over the last week I've seen two blog posts by the same person being recommended by Medium to me scoring programming languages in a laughable way to recommend their favourite niche languages.
That does way more damage to someone's hireability than a post about Python's print function.
Why don't you go play through Cyberpunk for a third time?
> This is because since it's on a single line, it is all buffered (packed) before we get it.
Usually. Depending on the environment. It's probably worth pointing out here that Python isn't controlling that buffering - print could have its own buffer, and it could be read that way, but it doesn't.
And buffering-to-newline is a common behaviour, but not necessarily a guaranteed behaviour. You may still wish to flush after a newline, depending on the platform.
Unless you're in REPL, in which case Python often tells the environment how it would like it to buffer, as part of the readline implementation.
What is the "Beyond" part? Seems more like just basics, that are already in the official docs.
He's just promoting his own blog piece.
Appreciate this very much. Had no idea print() did more than print.