15 Python Features You’ve Probably Never Used
Most people don’t know these incredible features of Python.

Today in this article I will show you the 15+ hidden features of Python you probably don’t know. These features I discovered from many websites and read many answers from StackOverflow and get the most useful features for you.
👉1# — Function Argument Unpacking
Do you know you can unpack a list or dictionary as a function argument using * and ** . This is very useful when passing a tuple, list, and dictionary as arguments containers in function.
def fun(x, y):
# do something
print(x, y)foo1 = [2, 5]
foo2 = {'x':2, 'y':5}
fun(*foo1)
fun(*foo2)👉2# —String Style Formating
You can do String style formating using format method and the keyword f. In the format method, you pass a dictionary which key value will replace in the String by match key in the curly braces {}.
#method 1print("I'm a {foo} and {bar} Developer".format(foo="Programmer", bar="Android"))#method 2foo = "Programmer"
bar = "Android"
print(f"I'm a {foo} and {bar} Developer")👉3# — In place Value Swapping
Normally you swap values with a help of a third-party variable temp. But you can do this in an easy and fast way without using any temp variable.
# old method
a = 5
b = 6
temp = a
a = b
b = a
print(a, b) # 6 5# new method
a = 5
b = 6a, b = b, a
print(a, b) # 6 5👉4# — Dictionary Get() Method
Dictionary has a get() method which had the same functionality as same we access the data of the dictionary. But in benefit, unlike dictionary bracket value access method which give exception when a key is not available, Get method returns None.
dic={1 :2, 3: 5, 6:8}print(dic[8]) #IT will throw an Errorprint(dic.get(8)) # None👉5# — Step Argument
The step argument is used as a slice operator to slice a list. Take a look at the below to know how it works.
a = [1, 2, 3, 4, 5, 6, 7, 8]print(a[::2]) # [1, 3, 5, 7]
print(a[::3]) # [1, 4, 7]#reverse a string
print(a[::-1]) # [8, 7, 6, 5, 4, 3, 2, 1]👉6# — List Comprehension
List comprehension in my opinion is the best and fastest way to iterate and putting conditions on the loop. Within the single line code, you can do multiple things.
# finding even numbers from a list
a = [1, 2, 3, 4, 5, 6]result = [even for even in a if even % 2 == 0]print(result) # [2, 4, 6]👉7# — Chain Comparison
Chain comparison is an interesting feature of Python to do multiple comparisons in a chain. Let say you do x < 10 and next, you do 10 > y but with chain comparison, you can do this in a single line.
a = 5
b = 2
c = 4print(a > 10 > b) # false
print(a < 10 > b) # True
print(a < 12 < b > c) # False👉8# — Multiple Assignments
Language such as C, Java, C++ allows declaring a single variable with a single value at a time. But in Python you can do multiple assignments. In simple words declaring multiple variables and assign them at the same time.
a, b = 4, 5a, b, c, d = 1 , 2, 3, 4#multiple list assignment to variblel = [1, 2]
a , b = l👉9# — For/Else statement
You are familiar with Conditional Statements in Python. But do you know about the For else clause ?.
a = [1, 2, 3, 4, 5]for x in a:
if x == 0:
break
else:
print("0 is not found in list")This code will run the else statement when the for loop is successfully run without any break. If we had 0 in our list that means if the statement is true and then in that case else statement will not execute.
👉10# —Negative Indexing
In Programming language you know we can access data with 0 to any positive number. But Python allows to access the data with a negative index. Negative indexing access data from backward.
# negative index
lst = [1, 2, 3, 4, 5]print(lst[-5]) # 1print(lst[-1]) # 5print(lst[-3]) # 3👉11# — Emoji in Python
Do you know python allows you to print emoji as a string? You can print specific emojis by Unicode or CLDR names. Check out the below code example.
#By Unicodes# grinning face
print("\U0001f600")
# grinning squinting face
print("\U0001F606")#By CLDR Names# grinning face
print("\N{grinning face}")
# slightly smiling face
print("\N{slightly smiling face}")👉12# — Sequence Multiplication
You can double the data in Python by multiplying with any positive number. Take a look at the below code to know how it works.
d = "abc" * 3
print(d) # abcabcabcd = [1,2,3] * 2
print(d) # [1, 2, 3, 1, 2, 3]👉13# — Zen of Python
Did you know Python had a secrete module name “this” which shows the Zen of Python? According to Wikipedia, it is a collection of 19 “guiding principles” for writing computer programs that influence the design of the Python programming language.
The Zen of Python, by Tim PetersBeautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!👉14# — Flatten List with Sum
You Should know about flattening a list with a map() built-in function. But Python had a feature to do the same work with the sum() built-in function.
lst = [[1, 3, 4], [3, 34, 9, 0, 1], [94 ,5]]print(sum(lst,[])) # [1, 3, 4, 3, 34, 9, 0, 1, 94, 5]#Note this feature not work on highly unordered list👉15# — Anti-Gravity
Do you know Python had a hidden module name antigravity. When you import that library and execute the code. Python will open your browser and redirect you to a website. Want to know about the website, Try out the following code now.
import antigravityFinal Thoughts
Well Python is no doubt is an awesome programming language and it’s fun to try some crazy fun stuff on it. I hope you find those features interesting and fun to learn. Feel free to share your response or a snippet that you believe is useful for Python Programmers.
If you found this article helpful, click the ❤️ button below and share the article on Facebook or Twitter, or any of your social media so your friends can also benefit from it too.
Learn More
If you had enjoyed this article, then you should take a look at my other programming articles.
