Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: Easy to understand intro to Python (github.com/thewhitetulip)
82 points by thewhitetulip on Feb 11, 2017 | hide | past | favorite | 33 comments



Fixed :-)


There are some factual errors in the introduction.

> Python has been around for more than 30 years

The license says that development began in the early 90s.

The factual errors continue in the explanation of the language, such as describing a triple quote string as a multiline comment.


Python was conceived in the late 1980s[1] and its implementation was started in December 1989[2] by Guido van Rossum at CWI

I might have misstated. The idea was around more than 30yrs albeit the implementation has been for around 27yrs

> triple quote string as a multiline comment.

Don't you use triple quoted string as a multi line comment? Then what do you use for multi line comment? I am curious.


Note that it is good practice to use "docstrings" in python:

    def demo():
      """I'm a demo. Maybe a few lines of
      doctests below.
      """
      return 42
You can now, for example in ipython do: help(demo) and get the demo.__doc__ back. See also doctests.

So no, they are not comments - they are part of the code -- but they are often used to comment on, and document the code.

docstrings pep: https://www.python.org/dev/peps/pep-0257/

docstring definition from the python docs: https://docs.python.org/3.5/glossary.html#term-docstring

doctest: https://docs.python.org/3.5/library/doctest.html?highlight=d...


Docstrings are part of the metadata of the object. Comments are not.


String literals without assignment have no side effect, that is why you think of them as comments. They are however, not comments. They are parsed and interpreted just like any other string.

You might be familiar with the concept in Javascript, if you have ever put 'use strict' at the top of a JS file.


I think thewhitetulip has GvR's blessing[0]. It makes sense, though:

  There should be one-- and preferably only one --obvious way to do it.
  Although that way may not be obvious at first unless you're Dutch.
The guy's handle is thewhitetulip, which is the most Dutch thing I can think of.

[0]: https://twitter.com/gvanrossum/status/112670605505077248


I am not Dutch, the handle is thewhitetulip because of a TV show called Fringe, where in the protagonist asks God for a sign of forgiveness, a white tulip.


Funny, I guess he's changed his mind.


What's so funny? I made a mistake and you and the others pointed it out & I fixed it.

Plus, triple quoted strongs are either strings or docstrings not comments, isn't rectifying mistakes good?


Hmm? I was talking about Guido changing his mind.

I guess it was an ambiguous pronoun reference. Sorry about that.


True, they are not strings and I'll update it to mention that specifically, we should not be abusing strings :-) thank you


Well, they are strings.. they're just multi-line strings..


Yes, I wanted to use "comments" instead of strings :D


Triple quoted string is just a way to write a string in multiple lines. There is no multi line comment in Python.


Yes, indeed. Triple quoted strings are just a way to write strings, but isn't that also a suitable way to write multiple line comments? The reason behind it is that otherwise you'll have to add `#` to every file and it becomes tedious! I have been using triple quoted strings as comments for a long time. But you are right, that's not the exact usecase for triple quoted strings, so I'll state that clearly.

Thank you!


Please no. Most editors have a comment/uncomment function which you can use on multiple lines at once. Abusing triple quoted strings for commenting is bad practice. I'd avoid it out of principle, because it's semantically the same as proper strings and looks the same with code highlighting, so it increases cognitive load. But also because they might be interpreted as docstrings mistakenly, either by other programmers, or the documentation tool itself.

A good rule, especially for beginners, is that triple quotes are primarily for docstrings, and the occasional multi line string. (Too many multi line strings, and it's probably a good idea to put them in a separate file)

Edit: There's also other errors with this "anti-book", including basic stuff like operators. For example, the major operator list at the top is missing "or", the Boolean part probably needs a bit more info on truthiness as "not" works on non-Boolean types also, and the membership test operator ("in") works on many other data types, not just lists. And of course, "!=" == "xor".


True, I am updating the multi line comment as doc strings and will include your comments, thank you!

Also 'or' is not missing from my "anti-textbook", or is present, I am not sure why you think so. I am yet to reciew thr tutorial once so hopefully mistakes like the in operator would be rectified soon!

Thanks :-)


If you're using vim, press control-V and move your cursor up or down to create a vertical block. And if you're not, ya gotta get yourself some vim ;)


I am yet to learn how to do vertical edits though, I use macros for that.


There are no multiline comments. Guido has said that if you want to quickly comment multiple lines, use a good text editor.


> 30 years

You also claimed that Python 3 was written to fix 30-year-old mistakes. Python 3 has been around of a while now.


True, that's a mistake. I think Python 3 has been around since 5+yrs I guess. My bad, sorry.


The tone of the writing in the "anti-textbook" suggests carefully researched facts, at least in some parts. It seems misleading to merely guess. I suggest you put some effort into giving citations for the various assertions. Links to relevant PEPs or sections of the official tutorial would be good.


That is a really good idea :-)

I'll do that right away


It's clear that this represents a lot of work and it's wonderful that you've done this. My instinctive reaction is to correct minor issues, but please don't take negative comments as a lack of respect for what you've done... this is a tough audience, maybe the toughest. Keep up the great work!


I don't take any feedback the wrong way, if you find any mistake, I invite you to send a PR or raise an issue :-)

Thank you!


I have just started learning Python and I'm referring "Problem Solving with Algorithms and Data Structures using Python". Should I continue with that or refer something else?


"Problem Solving" is a good reference for understanding algorithms and data structures. It uses Python but Python language is not its main focus. However, "Problem Solving" is one of the best places where I've learnt programming.


True, problem solving books would teach how to approach problmems but not the language itself.


Depends, are you a kickass Java dev looking to learn Python, or are looking to learn to code with Python as your first language? If the second what do you want to do with it? Automate some boring task or become a professional developer?


I have never heard of that book, I am sorry. You can start with yhe Documentation, there is an official tutorial in it & it is pretty informative




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: