5 Essential Python Tips And Tricks For Beginners

Python is one of the most preferred languages out there. Its brevity and high readability makes it so popular among all programmers.
So here are few of the tips and tricks you can use to bring up your Python programming game.

1. In-Place Swapping Of Two Numbers.

x, y = 10, 20
print(x, y)
x, y = y, x
print(x, y

2. Reversing a string in Python

a =”GeeksForGeeks”
print(“Reverse is”, a[::-1])

3. Chaining Of Comparison Operators.

n = 10
result = 1 < n < 20
print(result)
result = 1 > n <= 9
print(result)

4. Use Of Enums In Python.

class MyName:
Geeks, For, Geeks = range(3)

print(MyName.Geeks)
print(MyName.For)
print(MyName.Geeks)

5. Checking if two words are anagrams

from collections import Counter
def is_anagram(str1, str2):
return Counter(str1) == Counter(str2)
print(is_anagram(‘geek’, ‘eegk’))

print(is_anagram(‘geek’, ‘peek’))