r/learnprogramming • u/[deleted] • Apr 06 '18
Awesome Python Cheat Sheet
Here is a great cheat sheet for Python by Laurent Pointal (whoever you are). Thanks a ton! :)
If you like this sheet, maybe you are interested in our own cheat sheet course consisting of 5 cheat sheets (keywords, basic and complex data structures, object orientation, and tricks).
51
u/Gobi_The_Mansoe Apr 06 '18
As of python 3.6 you can also use f strings instead of .format. So instead of "This text is variable: {}".format(variable) you can just use f"This text is variable: {variable}" . I find it much easier to keep track of what is going on.
9
u/bicyclepumpinator Apr 06 '18
whoah, I had no clue. Awesome feature which I'll surely use in the future, thanks!
3
u/agrzw Apr 07 '18
I've waited for this sugar for a long time, .format() syntax always looked a little bit ugly as for me, when you have prepared variables for formatting.
115
u/Righteous_Dude Apr 06 '18 edited Apr 06 '18
A warning for anyone who plans to print that two-page PDF:
(1) The first time I printed it, the colored text came out as very light gray which was illegible. On my second try, I updated my print settings to "Print all text as black". The colored text then came out as medium-gray which was legible (although still lighter than I'd like).
(2) The printed copy seems to be too small - on an 8.5"x11" page, it only appeared as about 6.5"x9". On my third try, I updated my print settings to increase to 125% size. The printed version then properly filled the page.
(Edit to add: I just realized that my browser's print settings had been to print at 70% size,
so my need to increase to 125% was maybe specific to me.)
16
10
13
u/DeliciousKiwi Apr 07 '18 edited Apr 07 '18
This isn't quite a cheat sheet because it's 26 pages, but it has similar formatting and I've found myself going back to it quite often. Definitely worth checking out:
Beginner's Python Cheat Sheet.
Also, original source: https://ehmatthes.github.io/pcc/cheatsheets/README.html
3
1
10
Apr 06 '18
I have minicopies of these cheatsheets under my glass desk.
It's like I am literally cheating at job.
3
1
14
u/LemonsForLimeaid Apr 06 '18
As someone trying the the into to comp sci using python on edX, please excuse the stupid question. I know it says for Python 3 up top, but can I use this for python 3.5 as well?
10
2
u/woja111 Apr 06 '18
There's a big leap between Python 2 and 3. Python 3.x are more improvements but not groundbreaking.
2
u/mihirmusprime Apr 06 '18
I disagree. While it's been introduced recently, ordered dictionaries are definitely groundbreaking.
7
u/Denarb Apr 06 '18
Thanks a bunch, as someone who uses python every once in while this is awesome for remembering syntax!
3
3
3
1
2
2
2
2
u/smash_bang_fusion Apr 06 '18
Looks like he does CS research in france! https://perso.limsi.fr/pointal/
2
2
2
2
u/AkshayD110 Apr 10 '18
Opening a file for reading or writing should always be done using "with". That ways f.close() (closing of file) is taken care with in .
1
1
1
1
1
1
0
Apr 06 '18
[deleted]
4
u/Righteous_Dude Apr 06 '18 edited Apr 06 '18
There's a company called "BarCharts" that makes "Quick Study" laminated pages for various topics.
See these search results.
By the way, one of the pages found by that search was this long page at princeton.edu which had a link to this 30-page PDF about typical compile and runtime errors in Java, which looks like it would be helpful to those learning Java.
2
1
27
u/paradox_hunter Apr 06 '18
This is brilliant! Is there a similar resource for C as well?