7 Essential Python Tips And Tricks For Programmers

Sagardhiman
2 min readApr 4, 2022

--

In this article we will discuss about the python tricks and tips which must known to the python developer.

Source: Google

Before starting the article we will discuss what is python and why we need to learn python i.e. its application.

What is python?

Python is a computer programming language often used to build websites and software, automate tasks, and conduct data analysis. Python is a general-purpose language, meaning it can be used to create a variety of different programs and isn’t specialized for any specific problems.

It is used for:

  • Web development (server-side).
  • Software development.
  • Mathematics.
  • System scripting.

This tutorial is beginner friendly, if you are new to programming and want to start a new programming language and your choice is Python. then you are at right place.

In this article we discuss about the some basics things we need to be understand while learning python.

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

Reversing a string in Python:

a = "medium"
print("Reverse is", a[::-1])

Output:

Reverse is muidem

Create a single string from all the elements in list:

a = ["Medium", "and", "Quora"]
print(" ".join(a))

Output:

Medium and Quora

Chaining Of Comparison Operators:

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

Output:

True
False

Print The File Path Of Imported Modules:

import os
import socket

print(os)
print(socket)

Output:

<module 'os' from '/usr/lib/python3.5/os.py'>
<module 'socket' from '/usr/lib/python3.5/socket.py'>

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

Check The Memory Usage Of An Object:

import sys
x = 1
print(sys.getsizeof(x))

Output:

28

Conclusion:

This article is good for beginners python Programmers. Please comment below if you found this article useful and subscribe to the newsletter for the latest Article updates. If you want to learn File system in python and want to create projects in python comment below.

Thanks!

--

--