r/learnpython • • Aug 16 '16

Beginner's Python cheat sheets - updated

In the spring I posted a set of cheat sheets aimed at beginners, and many people found them useful. I've since completed the set of sheets, and wanted to share the full set. The additional sheets cover files and exceptions, testing, Pygame, matplotlib, Pygal, and Django.

You can download individual sheets, or download a pdf that includes all the sheets in one document. These sheets aim to remind you of Python's syntax, but they also include brief explanations of the concepts behind the syntax as well.

I wrote these sheets as supporting documentation for readers of Python Crash Course, but I think they're useful for beginners in general. I hope you find them helpful, and I'm happy to answer any questions about them.

447 Upvotes

52 comments sorted by

View all comments

Show parent comments

2

u/PurelyApplied Aug 16 '16

numbers = range(1, 1000001) since range returns a list (ie list() is unnecessary)

range returns a generator, not a list.

-1

u/[deleted] Aug 16 '16

Nope.

xrange does, however.

2

u/PurelyApplied Aug 16 '16

Yeah, as already mentioned, it was a misunderstanding of 2 vs 3. I always assume it's 3 in this sub unless there's evidence to the contrary, and hadn't actually looked through the sheets since I was on mobile.

I still haven't gone through the sheet in depth, but noticed that the corner claims "Covers Python 3 and Python 2". There are some significant differences that are worth explicitly mentioning, or it might be worth making separate sheets for 3 and 2.

Tagging OP for visibility. /u/ehmatthes

1

u/ehmatthes Aug 16 '16

I followed the same convention in these cheat sheets that I followed in the book. The material focuses on Python 3, but if something wouldn't work as shown in Python 2 there's a note about it.

For example, list(range(1,101)) doesn't cause an error in Python 2 so I didn't make a note about it. Classes in Python 2 should inherit from object, so there is a note about that.

1

u/zahlman zahlman Aug 17 '16

Would you consider making a note about using generators when you can get away with it and only explicitly dumping them into a list when necessary? :)