- Get link
- X
- Other Apps
8 Python Tips & Tricks That No One Included your Teacher or any Paid Course won't Teach You
Python is one of the top languages out there. Its brevity and high readability make it so popular among all programmers.
So here are a few of the tips and tricks you can use to bring up your Python programming game.
1. Print The File Path Of Imported Modules
import os
import math
print(os)
print(math)
Output:
<module 'os' from 'C:\\Users\\User\\AppData\\Local\\Programs\\Python\\Python39\\lib\\os.py'><module 'math' (built-in)>
2. Check The Memory Usage Of An Object
import sys
x = 1
print(sys.getsizeof(x))
Output:
28
3. In-Place Swapping Of Two Numbers.
x, y = 10, 20
print(x, y)
x, y = y, x
print(x, y)
Output:
10 20
20 10
4. Create a single string from all the elements in list
a = ["Python", "is", "Easy"]
print(" ".join(a))
Output:
Python is Easy
5. Reversing a string in Python
a = "Python is Easy"
print("Reverse is", a[::-1])
Output:
Reverse is ysaE si nohtyP
6. Print string N times
n = 2
a = "Python is not hard!\n"
print(a * n)
Output:
Python is not hard!
Python is not hard!
test = [1, 2, 3, 4, 2, 2, 3, 1, 4, 4, 4]
print(max(set(test), key = test.count))
Output:
4
8. Return Multiple Values From Functions
def x():
return 1, 2, 3, 4
a, b, c, d = x()
print(a, b, c, d)
Output:
1 2 3 4
I am sure you didn't know about these python tricks ;) Still, if you have any confusion or suggestions then comment below.
Happy Coding :)
python, python tips, python tips and tricks, python programming, python tutorial, learn python, python tips and tricks for beginners, python tricks, how to learn python, python quick tips, python tutorial for beginners,20 python tips and tricks, python tips for beginners, tips for learning python, python programming tips, python tips and tricks advanced, tips,5 python tips, python top tips, how to learn python fast, top 10 python tips, python project, tips to learn python, python -m
- Get link
- X
- Other Apps
Comments
Post a Comment