Python Functions With Examples

Function in Python

Recently, we conducted a session for the New York Python use group, where we discussed Functions in Python. In this tutorial, I will show you Python functions, how to define them, and a few examples of them. A function in Python is a reusable block of code designed to perform a specific task. It is … Read more

How to Skip an Iteration in a For Loop in Python?

Skip an Iteration in a For Loop in Python

While working with loops in Python, one of my team members was recently required to skip an iteration for a loop in Python. I suggested different methods. In this tutorial, I will explain how to skip an iteration in a for loop in Python using different methods with examples. Here, I will also show you: … Read more

For Loop In Python With Index

for loop in python with index

In Python, a for loop allows you to iterate over sequences like lists, tuples, and strings. However, there are times when you need not only the sequence elements but also their indices. In this tutorial, I will explain everything about the for loop in Python with index. To access both the index and the value … Read more

Do While Loop in Python

Do-While Loop in Python

Python does not have a built-in do-while loop. Despite this, you can still emulate this behavior using other Python constructs. In this tutorial, I will show you how to achieve do-while loop functionality in Python with some practical examples. To emulate a do-while loop in Python, you can use an infinite while True loop combined … Read more

How to Check if an Environment Variable Exists in Python?

Check if an Environment Variable Exists in Python

Recently, I received a query regarding how to check if an environment variable exists in Python. This is a little tricky, but there are different ways to do it. In this tutorial, I have explained how to check if an environment variable exists in Python. To check if an environment variable exists in Python, you … Read more

Python For Loops

for loop in python

While discussing over weekend sessions at the Python New York user group, I thought about writing about Python for loops with some examples. In this tutorial, I will explain everything related to for loop in Python, like its syntax, usage, and a few examples. What is a For Loop in Python? A for loop in … Read more

How to Stop a While Loop in Python

how to stop while loop python

Recently, I was working in a while loop in Python and got a scenario to stop the loop prematurely based on specific conditions. I researched it and found our different methods. In this tutorial, I will explain different methods to stop a while loop in Python with some examples. To stop a while loop in … Read more

How to Reassign Variables in Python?

python reassign variable

In Python, variables can be easily reassigned to new values, even if they are of a different data type. In this tutorial, I will explain various methods of reassigning variables in Python with examples. To reassign a variable in Python, simply use the assignment operator (=) to assign a new value to an existing variable. … Read more

Python While Loop Break and Continue

python while loop break and continue

In today’s tutorial, I will focus only on using break and continue in a Python while loop. I will show you how to use break and continue in Python while loops. A while loop in Python repeatedly executes a block of code as long as a given condition is true. Here’s a simple example: This … Read more