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

0

u/[deleted] Aug 16 '16

[deleted]

2

u/KimPeek Aug 16 '16

No, to combine strings you use the join method. Using .format() is a handy way to insert a variable into a particular point in a string. While your way works in this instance, it will become unusable if you try to join a list or variable quantity of words into a sentence or something similar.

3

u/sgthoppy sgtlaggy Aug 16 '16

'{} {}'.format(first, last) and ' '.join((first, last)) are synonymous in this case, but note that in the join line, you need to put the variables into a list/tuple.

I see and use format more often when combining separate variables, while I see and use join more often when operating on a list.