DEV Community

loading...

Discussion on: My beloved Python cheat sheet

Collapse
hekitakai profile image
Hekitakai • Edited

It's very good cheat cheet, but it need some improvements:

  • you missed kwargs in say_hello function
  • in file and exception paragraph indentation is wrong
  • Naming scope is also a little wrong. Single underscore is more protected value than private. It can still be accessed from outside. Private is double underscore, which triggers name mangling.
  • Mixin part seems wrong to me - mixin should add functionality, not overwrite. I thing it would make more sense to use foo and bar instead of test. As it is now it looks more like multiple inheritance and mro at work.

To your list you can add:

  • slicing and range - you can use 3rd parameter to change order and how list is sliced: [1, 2, 3, 4, 5][::-2] -> [5, 3, 1]
  • datatypes: missing sets and tuples (I know this is later, but still)
  • else statement for for loops
  • more verbose variable unpacking (enumerate and items use it) and cool things you can do with it: a, b = b, a; a, _, _, d = (1, 2, 3, 4)
  • while you were on list unpacking you could add updating dictionary (Python 3 only): a = {'a': 1, 'b': 2}; b = {'b': 3, 'c': 4}; c = {**a, **b} => {'a': 1, 'b': 3, 'c': 4}