Member-only story

The Best Ways To Optimize Your Python Code

Manpreet Singh
3 min readMar 26, 2022

--

Welcome back! Python is an awesome programming language with a ton of capability, if you’re new to Python, check out the link below to learn more about it:

So, let’s take a look at a few ways you can optimize your Python code!

Changing Your While Loops

Another interesting way to speed up your Python code is within your while loops, there are times where you may use the following line:

while True:
#code down here

A faster way to write an infinite loop is by using 1 instead of True:

while 1:
#code down here

Updating Python

Another way to increase the speed of your Python code is by updating your Python version, there are new versions of Python coming out all of the time, so staying on the most recent version may speed up your run time. Also, sooner than later the Python development team is going to make speed their main priority, so by being on the latest version you can ensure that you will be running the…

--

--

Manpreet Singh
Manpreet Singh

No responses yet