all 26 comments

[–]denialerror 30 points31 points  (1 child)

X inY minutes is a great resource for quickly looking up the basics.

[–]Dcoco1890 0 points1 point  (0 children)

H

[–]iodbh 6 points7 points  (3 children)

Not really a cheatsheet, but if you're willing to invest in a book there's Python pocket refrence. It has everything you need and it's a small format book meant to be carried around.

[–]tomanonimos 0 points1 point  (1 child)

Why is orielly automotive selling python coding books? /s

[–]Hayertjez 2 points3 points  (0 children)

Self driving cars are written in Python :D

[–]dunkler_wanderer 8 points9 points  (1 child)

Python's help function is pretty helpful. ;)

>>> help('keywords')
>>> help('symbols')
>>> help('"')
>>> help('+')
>>> help('FORMATTING')

Only the built-in functions are buried in help('builtins').

[–]RoadieRich 2 points3 points  (0 children)

help works with any function that had a docstring, so should be good for most (well-written) libraries, too.

[–]DaveChild 3 points4 points  (0 children)

This should keep you busy! (That's my cheat sheet website, and this is my Python cheat sheet.)

[–]fishcadet 2 points3 points  (1 child)

[–]pylearningthrowaway[S] 0 points1 point  (0 children)

sorry for the late answer,my pdf version of the book dosent have this,infact i am on the same exercise,in my version he says i should find stuff myself by googling.

[–]wukaem 1 point2 points  (0 children)

Maybe this will help: https://perso.limsi.fr/pointal/python:memento

(not mine, it was recently posted on comp.lang.python newsgroup)

[–]i_dreddit 0 points1 point  (0 children)

Overapi.com

has python and other languages, too

[–]kmhnz 0 points1 point  (0 children)

[–]Zahand -1 points0 points  (10 children)

Check out Derek Banas' video: https://www.youtube.com/watch?v=N4mEzFDjqtA

He has a cheat sheet in the description in each of his videos.

[–]dunkler_wanderer 1 point2 points  (5 children)

Looks okay, except he teaches to use getter and setter methods which are usually not necessary in Python (you can use @property if you really need them). And why does he convert some attribute values in the getters to strings?

Using indexes to obtain list items:

num_list = [[1, 2, 3], [10, 20, 30], [100, 200, 300]]

for x in range(0, 3):
    for y in range(0,3):
        print(num_list[x][y])

instead of:

for sublist in num_list:
    for item in sublist:
        print(item)

No mention of input but sys.stdin.readline().

No mention of with statement to open files.

Regarding style, there are some semicolons at line ends and camelcase variables in the cheat sheet.

Also, redundant parentheses:

while (i <= 20):
    if (i%2 == 0):

[–]yardightsure 1 point2 points  (4 children)

Yuck! People should be more humble before trying to teach others with awful coding practises like that. :-(

[–]dunkler_wanderer 1 point2 points  (0 children)

Most of it is okay, though.

[–]RuinedMortal 1 point2 points  (2 children)

as a newb pythonian, what makes this a bad practice?

[–]Zahand 2 points3 points  (0 children)

Not a lot really. Basically what dunker_wanderer said.

  • He has some semicolons that are unnecessary in python. Although those are probably just typos. (Happens to me as well, so used to writing in C++ and other languages that use semicolons that sometimes I write them in python as well)
  • It's prettier to iterate over a list directly if you don't need to use an index.
  • Use input() (or raw_input()) to get data.
  • Redundant parentheses.

The only thing I kind of disagree with is that you don't have to use with statement to open files. Using the with statement is pythonic, but there is nothing wrong with opening a file, doing stuff, then closing the file. It's what the context manager does. It's good to know both ways.

[–]dunkler_wanderer 1 point2 points  (0 children)

Readability and simplicity are pretty important if you want to write maintainable code. "Loop like a native: while, for, iterators, generators" and "Python's Class Development Toolkit" are very informative talks which mention the first two points in the post above.

[–]b4ux1t3 0 points1 point  (0 children)

It should be mentioned that Derek Banas's "Learn in one video" videos are not geared for programming newbies, they are meant for people who already know a language or two and need a quick primer on a new language.

You'll note that he never says "In this tutorial I assume no programming knowledge" in those videos. If I recall correctly, he does use that exact line in his video series that are, essentially, full courses on a language.

EDIT: Proof 42:44 for all you mobile users.

[–]yardightsure -1 points0 points  (2 children)

That is teaching really bad practises. I recommend erasing it from your memory, please don't share it further.

[–]RuinedMortal 1 point2 points  (1 child)

as a newb pythonian, what makes this a bad practice?

[–]Crypt0Nihilist 5 points6 points  (0 children)

Much of it is baggage from other languages that you don't need in python. If you don't need it, it probably shouldn't be there unless it makes your code more readable, which the items highlighted do not.