Maxim Danilov
1 min readAug 30, 2022

--

Alex Murphy, this is dev.genius blog and not the copy-paste python tutorials.

All thau you write is base of Python. This is a Standart and not the "useful tricks".

1. rounding

copypacte from https://docs.python.org/3/library/functions.html#round

2. Reversing a String

str[::-1] vs str(slice(None, None, -1)) First is a standart, second is a trick.

3. Joining Strings

a = ("a", "b", "c", "d", "e", "f", "g", "h")

' '.join(a) vs reduce('{} {}'.format, a[1:], a[0]). First is a standart, second is a trick.

4. Joining Strings with Filter

bad bad way. filter, lambda... wtf. Are you a python programmier?

' '.join(_ for _ in a if _ != 'NOT')

6. With Statement

copy paste from https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files

7. Chaining comparison

Wow. Really.

result = 0 < 0 == 0 # tell me result

8. Underscore as a “throwaway”.

Really. How it works in my 4. example?

9. Swapping Variables

Famous feature in python. Standart. And this is Unpacking arguments.

it works also for many variables:

a, b, c = 1, 2, 3 # ...

a, b, c = b, c, a # ...

10. Print string no of times.

The multiplication operator (*) prints a string multiple times in the same line. What?

multiplication operator dont print nothing! it help you create a repeated string.

print function - print your string ONLY ONE TIME.

OMG.

--

--

Maxim Danilov
Maxim Danilov

Written by Maxim Danilov

Python & Django Developer and speaker

No responses yet