r/learnpython • • May 30 '20

Python cheat sheet?

I was wondering whether you guys keep a handy cheat sheet when y'all code. For example when working with a module after a long time it's obvious that we become rusty and need help with the functions and the syntax. Would be great if you guys share the links/books that you guys refer to while programming. I'm sorry if this has been asked before. Cheers!

372 Upvotes

50 comments sorted by

173

u/bloztorch May 30 '20

Here are some cheat sheets by the author of Python Crash Course

11

u/puresuton May 30 '20

Currently reading/working through Python Crash Course, so thank you! This is really cool and a great resource to have!

1

u/Link0fthewild May 31 '20

This book helped me a lot as a complete beginner in programming. And the cheet sheets are super handy

1

u/nitzanelad10 May 31 '20

Highly recommended

41

u/MikeTheWatchGuy May 31 '20 edited May 31 '20

It's odd you mentioned this as I normally am not really looking or on the lookout for one, but last night I found what I think could possibly be the best I've ever seen.

https://gto76.github.io/python-cheatsheet/

A few things unusual about this cheatsheet.

  • It's up to date / updated. The last update was March 15, 2020

  • It's "comprehensive" and it most certainly is! Covers MANY of the popular packages along with the language itself.

  • It's huge. The PDF I created for easy searching is 52 pages

  • It's almost entirely code, that is color coded

I'm trying to figure out exactly how to integrate it into my workflow. It's so powerful that I could see it being used often, but i'm not sure how to integrate it with PyCharm or other tools.

[EDIT] My runner up and winner of most colorful and most data per square centimetre is John Oakey's https://www.wikipython.com/ . If you're looking for tkinter cheat-sheets, his are among the best.

2

u/camposthetron May 31 '20

This is so good! Thank you!

2

u/Dimbreath May 31 '20

The first one is so good. I learned quite a few stuff from it.

1

u/OnlySeesLastSentence May 31 '20

I used to have a bootleg Chinese iPhone and a gif of that guy (I think it's Chaplin?) dancing would play on the built in music app.

9

u/schneedledee May 31 '20

Oh heavens. It's John Cleese. Of Monty Python.

Have we forgotten so soon the Ministry of Silly Walks?

https://youtu.be/BoIdEjdZIls?t=27

6

u/greebo42 May 31 '20

hard to believe that sketch is ~50 years old!

and dead parrot. and cheese shop. and spam. and ...

opportunity for a whole new generation to discover!

3

u/OnlySeesLastSentence May 31 '20

I haven't watched monty python. Sorry. :(

6

u/schneedledee May 31 '20 edited May 31 '20

Oh I was just teasing, don't take it hard. The show hasn't been on anywhere for years. No clips on youtube, that's why I had to link to an interview. (actually there are plenty of clips, i'm just failure at youtube searching: https://www.youtube.com/watch?v=eCLp7zodUiI )

But I do hope we won't forget where the name came from:

https://docs.python.org/2/faq/general.html#why-is-it-called-python

:)

Cheers, and may we all remember the importance of being silly.

38

u/danielroseman May 30 '20

If you're on a Mac, there's a really useful little utility called Dash that you can set to pop up and show you the docs for any class in any language. It's great, I use it all the time.

14

u/kosayoda import antigravity May 31 '20

On Windows and Linux, there's a similar open source offline documentation browser called Zeal.

3

u/[deleted] May 31 '20

Is there a free option?

8

u/Versaiteis May 31 '20

devdocs.io might be the best free alternative that I know

4

u/HolyRomanSloth May 31 '20

I use Kite.

1

u/isameer920 May 31 '20

Kite had documentations too?!

-1

u/hnguyen01122 May 31 '20

I feel bad for developers on Mac vs Linux. You’ll always get fleeced using a Mac.

3

u/toastedstapler import itertools May 31 '20

i love it. i had a macbook at work last year and chose to spend my own money on one. great trackpad, great screen, OS works super smoothly for my workflow. did i really get fleeced?

-1

u/hnguyen01122 May 31 '20

You should do your best to convince fortune 100 companies to spend money on Mac and not tell Developers to use Linux.

4

u/toastedstapler import itertools May 31 '20

people can use what they want to, i don't really care what others want to use. they can make that choice theirselves

3

u/danielroseman May 31 '20

Why, because someone who put work into an app wants to be paid for their time?

1

u/hnguyen01122 May 31 '20

I'm sorry what's the current stats on how many developers use Linux vs anything else?

25

u/[deleted] May 30 '20

Write one on your own. By the time you finished you won't need it anymore. It's a great exercise.

9

u/greatestbird May 31 '20

This is what I did. I made it more fun by getting into fountain pens at the same time. It motivated me to take more and more notes so I could try new inks/pens lol. Do not recommend getting into fountain pens, very expensive.

6

u/[deleted] May 31 '20

Yo. I know what you mean haha

1

u/MikeTheWatchGuy May 31 '20

Do not recommend getting into fountain pens, very expensive.

You can do it cheaply to start with. Parker and Lamy make some excellent starter pens.

I write everything on paper using pens and pencils!! All of my designs, notes, etc. I have a Cookbook of Python design patterns. For me, the act of writing things down burns it into my memory.

I've been begging John for a sample template that he uses - https://www.wikipython.com/

The PDFs say there were created using Microsoft Publisher. I SO badly want to make a PySimpleGUI one that's in his format!! Would be super-helpful. Although, docstrings can be just as / more powerful.

1

u/Traust Jun 01 '20

You can start off with inexpensive fountain pens but then one day you find yourself looking at $1000 pens thinking to yourself how much you need it to go with the other expensive pens you have brought cause you "needed" them. Same problem when you play D&D and War Hammer, you seem to end up with a mountain of dice and figurines. I swear however they are ALL useful and I NEED all of them.

1

u/camposthetron May 31 '20

Great advice, thank you!

27

u/Tweak_Imp May 30 '20

I just google stuff every time until I learn it.

2

u/[deleted] May 31 '20

How about help() function?

1

u/Phyan May 31 '20

The link has PDF of cheatsheet related to ML and AI. Though it has dedicated page for Python, Pandas and Numpy.

Cheat sheets in PDF

1

u/hnguyen01122 May 31 '20

I usually use cheat sheet as a quick hack to learn a new language. 😀

1

u/umognog May 31 '20

In a jupyter notebook, alt+tab (+tab...) when using a method.

first tab shows the main garb, second tab expands it and gives you a scroller, third tab does something fourth makes it longer while you type and disappear after 10 seconds.

1

u/[deleted] May 31 '20

I can really recommend to write your own little booklet in the style of a vocabulary book. As it’s structured by yourself, you’ll find the needed syntax almost immediately. For myself I also think that my brain processes the Material way deeper, as if I didn’t write it down by hand.

1

u/mat000111 May 31 '20

I have two things I do which I find helpful and will toss out there. First I usually make a directory called python and put sample code in it. I use this to learn how to use new things and then I use it as reference. The second is I tend to make a lot of wrapper classes for thing I use a lot. For example my configparser wrapper has some code to work with python 2 or 3. Checks that files are there before reading. I put the wrapppers into a git repo and move them from project to project.

1

u/ragnar_the_redd Jun 01 '20

Well except for the obvious (stack overflow).
Whenever i do something new in python, for work or part of any large project, I create an experiment entry in my private repository.

I take the new library or concept, or even just a complex data processing function i need to include in the big scale project and do it on a small scale. I often forget how i do things, and i can always return to the specific experiment to see it.

A lot of it goes out of date as external libraries or even python itself gets updated (well honestly just the 2.7 - 3.75 switch) But since it is short and focused i can simply look at it and remember what, how and why i did.

For example i once ran into some trouble with base64 encode decode - real basic stuff for people who work with it daily, but for me it was complicated because data went in right, but the receiving side failed to process because - as i know now - it didn't come out because of the way dict type objects were encoded.
Took me a couple of hours to understand that i have a problem, where i have it and why it's happening.
So now i have a "base64_experiment" where i have an example of structure sensitive encode/decode for various models.

That's my personal cheat sheet.

-15

u/cas4d May 30 '20

Needn’t and shouldn’t. For basic commands, you should pick up a project and write enough lines of codes so that you can remember them, looking at cheatsheets can make it harder to memorize; for packages, use documentations; for others, use google and stack overflow, should cover 99.9 percents of your problems.

0

u/[deleted] May 30 '20

[deleted]

4

u/cas4d May 31 '20

I believe most would agree more with you just by looking at the upvotes, I was actually believing i was making constructive opinions after articulation, but any way. And maybe you are right for some learners.

But I am still taking the chance to supplement a point in case: cheat sheet, for some and maybe not for all, can reduce the time of processing it in one’s mind simply because of functional and mechanical nature - you have a vague idea about what you want, and you know something lying in your reference could sort of achieve it and you look up.

But I would argue this is a great time to dive in what you really want in a particular context; why use A not B even if they spill out the same output; is performance an issue; can we make it friendly for future debug, etc. When you consider all aspects, you would realize to achieve sth you can potentially have hundreds of ways with different purposes in nature. Cheat sheet simply doesn’t tell you these, and reinforce a narrow perspective and limit you from trying different things, “I want to have output y from input x, there is one line in my cheat sheet does exactly that”. Any learner is expected to write thousands of shitty codes before good ones come, and shit codes by definition is still working codes, but just inappropriate. And have yourself fixated in the beginning makes it slower or even impossible to be a good coder.

The ultimate message of my school is that: it is ok to have a painfully slow beginning, keep forgetting so that you are exposed to opportunities of going up to StackOverFlow and read those discussion regarding a syntax question, and possibly learn an alternative way to achieve sth. The real enemy is really not being mindful enough when writing codes.