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.

10

u/bbatwork Aug 16 '16 edited Aug 16 '16

Actually it depends on the version of python you are using... Python 2.7 range returns a list, Python 3.5 range returns a generator, and xrange doesn't even exist, it was renamed range.

And looking at the cheat sheets, it seems to be written for version 3, so the example is correct.

1

u/[deleted] Aug 16 '16

I see!

I was not even thinking about Python 3.x. Thanks for pointing that out :)

2

u/bbatwork Aug 16 '16

I do the same in reverse all the time :)