Settings

Theme

Python Print() and Beyond

josiasdev.best

49 points by josiasaurel 6 years ago · 22 comments

Reader

cbarrick 5 years ago

The 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.

  • Something1234 5 years ago

    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.

    • oefrha 5 years ago

      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.

      • Something1234 5 years ago

        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.

    • fireattack 5 years ago

      If you already know what you want you can simply add "docs.python.org". It's more work but it's worth it.

      • watt 5 years ago

        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?

        • fireattack 5 years ago

          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.

          • dvfjsdhgfv 5 years ago

            > You (we) have little control of how search engine works

            Complaining on HN can sometimes work miracles.

  • amingilani 5 years ago

    Yes, but this article explained it in a more interesting way which makes it easier to remember.

fireattack 5 years ago

> 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".
elgatonegro 5 years ago

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.

  • markdown 5 years ago

    > 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.

    • njharman 5 years ago

      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.

  • amingilani 5 years ago

    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.

  • Jonnax 5 years ago

    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.

  • kordlessagain 5 years ago

    Why don't you go play through Cyberpunk for a third time?

shakna 5 years ago

> 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.

Tempest1981 5 years ago

What is the "Beyond" part? Seems more like just basics, that are already in the official docs.

for_i_in_range 5 years ago

Appreciate this very much. Had no idea print() did more than print.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection