15 Python tips and tricks, so you don’t have to look them up on Stack Overflow

Practicus AI
2 min readJul 23, 2019

Want to be inspired? Come join my Super Quotes newsletter. 😎

Tired of searching on Stack Overflow every time you forget how to do something in Python? Me too!

Here are 15 python tips and tricks to help you code faster!

(1) Swapping values

x, y = 1, 2
print(x, y)
x, y = y, x
print(x, y)

(2) Combining a list of strings into a single one

sentence_list = ["my", "name", "is", "George"]
sentence_string = " ".join(sentence_list)
print(sentence_string)

(3) Splitting a string into a list of substrings

sentence_string = "my name is George"
sentence_string.split()
print(sentence_string)

(4) Initialising a list filled with some number

[0]*1000 # List of 1000 zeros 
[8.2]*1000 # List of 1000 8.2's

(5) Merging dictionaries

x = {'a': 1, 'b': 2}
y = {'b': 3, 'c': 4}
z = {**x, **y}

(6) Reversing a string

name = "George"
name[::-1]

--

--