Learn Python in minutes
learnxinyminutes.com
learnxinyminutes.com
x = """aaa
bbb"""
And you can also use single quotes if you want. x = '''aaa'''
The reason this might have been confused with a comment is because triple-quoted strings are often used for documentation strings, a Python feature that gives special meaning to string literals that occur as the first statement in a function or class. Those strings get associated to the function as its documentation and can even be inspected at runtime: def foo():
"my documentation string"
return 17
print help(foo)I remember picking up a large book from a store shelf titled something like "Python for Programmers". Thinking, "Oh, this is for people who already know how to program and just want to learn Python". I open the book randomly and start reading it's explanation on what functions are in programming and why they're useful. I sighed and placed the book back on the shelf.
[1, 2]
but is instead (1, 2)
The second line of that output also happens to be wrong, because printing a dictionary uses repr() on its keys and values and str.__repr__ normally uses single quotes, so instead of {"a": 3, "b": 4}
It will instead print {'a': 3, 'b': 4}
For that matter, I would prefer it if this guide used single quotes primarily; that is the preferred standard in Python.E.g., off the top of my head, mutable default arguments, or trying to catch multiple exceptions with "except Exception1, Exception2:". That's the kind of thing people new to the language can spend a lot of time debugging when they first run into it.
Edit: and any introduction to tuples should probably show how to write empty and one-element tuples, since that can be non-intuitive. Writing (1) instead of (1,) is also a fairly common gotcha.
I didn't want to overload the reader. Perhaps a more in-depth guide is required.
I am waiting for "Learn X While You Sleep--wake up as an expert!"
If Michael Jackson just knew that......
Great stuff!
As a sidenote, how does everyone take note (if you even do) when learning something new like a language or some kind of skill?
I learn better when I read the same thing over and over from different sources, which might have additional details or different points of view.
Not taking notes forces me to go back when I don't remember something, often finding new sources.
How would you improve the retention rate?
This article is meant for programmers from other languages who want to quickly look up a language specific detail.
This is a good cheat sheet.
but all snark aside, good work so far! like the concept.
Coming from a php background I had (and am having) problems wrapping my head around the packaging section. I started to lose interest because of it. It's as if I hit a wall.
Can any Python hackers offer some good resources for learning more about packaging?
http://learnpythonthehardway.org/book/ex46.html
If you email me with the problems you had I'll see what's wrong with the exercise and figure it out. There was a particularly stupid ordering problem with it where I had people install requirements after they needed them, so go double check it again and see if it got better.
Also, email me help@learncodethehardway.org with what you ran into. If you're in San Francisco I'll even meet you in person to figure out what you're doing live (works way faster).
I haven't been able to find a decent tutorial on creating packages. That particular section in "Learn Python the Hard Way" was hard for ME to follow. I was able to create a package but only after finding a link on stackoverflow question that then redirected me to a github page containing a sample package from an individual who also had problems. He states that his package worked but he wasn't sure if he created the package correctly.
I've tried reading the python documentation but I'm too dumb to understand some of the language. (No CS background, just a regular dude and a computer here.)
That would've been impossible because I wrote that 2 days ago =]
Add about line 89, before assignment to some_var,
a, b = 3, 4
Added a try-except around line 186, to guard the KeyError, try:
filled_dict["four"] #=> KeyError
except KeyError:
print "Raises a KeyError"
Added a definition of foo around 320, so calls would work def foo(*seq, **dict): passSorry for the nitpicking, but calling them primitive types, is just plain wrong.
Sorry for that. I know they are objects but if you consider everything an object then really you have no primitives except object itself. Certainly this has a place in programming philosophy but not really a helpful point in a language-primer/cheat sheet.
Kudos to whomever wrote it.
Glad you find it useful!
With or without the parens I'm getting the same result for "a, b, c = (1, 2, 3)"
(a, b, c) = (1, 2, 3)for you gurus, it's got a cool new feature: debugging Python & C++ together: http://www.youtube.com/watch?v=wvJaKQ94lBY
"I know kung-fu"