25 Useful Python One-Liners That You Should know



In this blog, I want to present some python one-liners which everyone should know.

1. Swapping Two Variables


# a = 4 b = 5
a,b = b,a
# print(a,b) >> 5,4

Let’s start with a simpler one by swapping two variables with each other. This method is one of the most simple and intuitive methods that you can write with no need to use a temp variable or apply arithmetic operations.

2. Multiple Variable Assignments


a,b,c = 4,5.5,'Hello'
#print(a,b,c) >> 4,5.5,hello<