Overview
The Python cheat sheet is a one-page reference sheet for the Python programming language.
If you like the cheat sheets, and want to say thanks, please consider buying me something from my Amazon Wishlist. Thankyou very much to those who have already hunted it down and sent me something - I'm very grateful!
Downloads
The Python Cheat Sheet is released under a Creative Commons License (Attribution, Non-Commercial, Share Alike).
Please note: If you wish to link to a cheat sheet from elsewhere, please link to this page so others find all available versions, the license and the description.
sys Variables
Python has a variety of built-in variables which give information about the system on which it is running.
sys.argv
sys.argv contains command line arguments in a zero-based list.
os Variables
In a similar fashion to the "sys" variables, Python also has built in variables which give information about the operating system on which it is running. This section also lists the "registered" OS names.
Methods
Python, as you might expect, has a huge variety of standard methods for working with strings, lists, files and classes, and this section lists those with, where possible, compulsory arguments.
Indexes and Slices
Indexes and slices have been known to trip up plenty of new programmers, and occasionally experienced programmers new to Python. This section of the cheat sheet shows by example how indexes and slices work in Python.
Date and Time
These sections of the cheat sheet include the DateTime and Time methods, as well as the various Date Formatting options available for the strftime and strptime functions.
Thanks
This is the second cheat sheet created with the involvement of the Cheat Sheets Google Group, and the first to include twitter (@CheatSheets). Many thanks to Charly Walther and Dan Horning for their suggestions and feedback. Finally, thanks also to the 1017 people who requested this cheat sheet!

26 Comments
Thanks for this. I jumped into django without knowing python too well and I will use this reference quite a bit while I catch up on all of the python I should know.
#1, Greg Allard, United States, 22 January 2009. Reply to this.
Thanks for the cheat sheet. I'd like to learn Python this year, and no doubt this will be invaluable!
Replies: #28.
#2, Paul, United Kingdom, 22 January 2009. Reply to this.
Thanks a lot...
But I have one question - why you don't place "Indexes and Slices" into first column and don't use whole second column for "Methods"???
Replies: #26.
#3, Steward, Ukraine, 22 January 2009. Reply to this.
@Greg, @Paul: Thanks.
@Steward: Just a matter of space. The middle column would be longer than the sheet if I had moved the class methods into it. I would have had to remove useful info.
#4, Dave Child, United Kingdom, 22 January 2009. Reply to this.
Oh... I see... maybe you can make blank rows more shortly :)
Replies: #25 and #26.
#5, Steward, Ukraine, 22 January 2009. Reply to this.
Thanks. Very nice sheet. Really useful at daily work.
Replies: #27.
#6, Benjamin, Germany, 23 January 2009. Reply to this.
Very nice.
Possible addition for the indexes & slices:
a[::-1] reverses a list ( [5,4,3,2,1,0] )
#7, Wes, United States, 23 January 2009. Reply to this.
As usual great stuff! A must read post for any newbie!
#8, Me, Unknown, 26 January 2009. Reply to this.
I've added a couple of extra items to the sys.argv list to demonstrate how command line attributes (e.g., -c and --h) work.
@Wes: Great idea. I've had a quick look and it's going to be tough to squeeze in but I'm sure I'll find a way.
@Benjamin, @Me: Thanks :)
#9, Dave Child, United Kingdom, 30 January 2009. Reply to this.
A very useful sheet. Cool!
#10, Keen, Diego, 10 February 2009. Reply to this.
I am getting ready to prep for a new python class. Thank you so much for your sheets. I send my student to your site often. :-)
#11, Valerie Shipbaugh, United States, 11 February 2009. Reply to this.
Damn your good! Came here for a Python cheat sheet and its on the front page!
#12, charlie, United Kingdom, 25 February 2009. Reply to this.
Hi! Yet another wonderful cheat sheet that I'll certainly be using from now on, thanks! The html, html character entities, css and javascript ones already help me a great deal and are all properly posted to the wall behind my monitor. The other ones I use are the PHP, regular expressions, subversion, MySQL, Ruby on Rails and microformats ones, though these ones are kept handy on a clipboard on the corner of my desk. This one is probably going to the clipboard too...
#13, Thiago Cavalcanti, Brazil, 6 March 2009. Reply to this.
Cool. Shorter than the famous http://www.limsi.fr/Individu/pointal/python/pqrc/. Can be useful.
#14, Kevin, Unknown, 10 March 2009. Reply to this.
I tried to add a few suggestions for cheat sheets but the add button is disabled. The ones I wanted to add were emacs, TeX and LaTeX.
#15, Steven Orr, United States, 14 March 2009. Reply to this.
Indexes and Slices
b=a[:] Shallow copy of a
This is not a shallow copy, or am I wrong?
#16, Artur, Poland, 18 June 2009. Reply to this.
Great one! Thanks a lot for your work.
#17, Ulli, Hannover/Germany, 3 July 2009. Reply to this.
I am doing a spanish translation of this cheatsheet to use in a brochure for my company at PyCon Argentina, and am creating the PDF using restructured text and rst2pdf. Here you can see what it looks like:
http://lateral.netmanagers.com.ar/static/machete.pdf .
Is that attribution good enough for you? I can change it :-)
#18, Roberto Alsina, Argentina, 26 August 2009. Reply to this.
#18 Roberto: That attribution is perfect, thanks. If you're happy for me to do so, I'd like to add a link to the Spanish version for others to use if they prefer - please let me know if that is ok and if so where you would like the link to point.
#19, Dave Child, United Kingdom, 26 August 2009. Reply to this.
Cool. As soon as it´ s ready I ´ll post the link here.
#20, Roberto Alsina, Argentina, 26 August 2009. Reply to this.
Done, posted my version at http://netmanagers.com.ar/machete (spanish and english), the sources are available in github.
This version is one A4 page, meant to be folded in 3.
#21, Roberto Alsina, Argentina, 27 August 2009. Reply to this.
Great work, Roberto! I've added the link above.
#22, Dave Child, United Kingdom, 28 August 2009. Reply to this.
Great article!!!
-- KIZILSUNGUR
#23, KIZILSUNGUR, Turkey, 16 October 2009. Reply to this.
I leran python for my django app. thx a lot
#24, clarissa, Germany, 24 October 2009. Reply to this.
where do you request new cheat sheets? one i'd like to see is perl
for direct responses from people rather than harvester bots, i can be reached on the gmail hosts and my account is erik.soderquist
#25, Erik, US, 21 January 2010. Reply to this.
That's already the 7th of your nice cheat sheets I downloaded.
Thanks a lot!
C.
#26, Constantin, GER, 14 February 2010. Reply to this.