Python Programming

4 Ways to Swap 2 Variables in Python

4 Ways to Swap 2 Variables in Python

Ways to Swap 2 Variables in Python: In computer programming, the act of swapping two variables refers to mutually exchanging the values of the variables. For example, if a = 5 and b = 6, then after swapping these two variables, a = 6 and b = 5. To perform this, there are many ways that one can follow. Here …

4 Ways to Swap 2 Variables in Python Read More »

What does if __name__ == “__main__”: do?

What does if __name__ == “__main__”: do? The best answer I found after searching for it in Google was in StackOverFlow. According to it, whenever the Python interpreter reads a source file, it does two things: it sets a few special variables like __name__, and then it executes all of the code found in the file. …

What does if __name__ == “__main__”: do? Read More »

Python Program to Send Emails Using Yagmail

Sending mail using yagmail

With Yagmail, sending e-mail using a Python program is easier than ever before. Yagmail – Yet Another Gmail/SMTP Client is a user-friendly API that simplifies the process of sending emails. In this post, I am going to share how to use yagmail, the API described above. If you want to read the full documentation of this …

Python Program to Send Emails Using Yagmail Read More »

What the F*** is F-string in Python

F-strings in Python

Python provides several ways to format strings. These different ways have their own advantages and disadvantages. Python 3.6 and above come with another method of string formatting (formally termed as string interpolation) known as f-strings” or Formatted string literals PEP 498. I knew about it recently while working on a Kattis problem with a friend.  …

What the F*** is F-string in Python Read More »

Differences between sort() and sorted() in Python

Sorting is a very common problem that many programmers may come across. Like any other programming languages, Python has its own built-in sorting methods. These sorting methods are sort() and sorted(). In this post, I will share the differences between these two methods and how these can be used in programs. I found these methods …

Differences between sort() and sorted() in Python Read More »

How to use Switch Case Statements Python

Python Switch Case Statements

Unlike many programming languages, you may know like Java and C, Python does not support switch case construct. I came to know about this while converting a Java program to Python program from a git repository. In this post, I am going to share how to implement switch case problems in Python so that you …

How to use Switch Case Statements Python Read More »

Why Not to Uninstall or Remove Python from Raspbian OS

Python comes installed along with many flavors of Linux. For Raspbian Operating System (OS), like some other Linux-based OSes, both Python 3 and 2.7 comes installed by default. Raspbian OS is a light-weight operating system for Raspberry Pi, a credit card-sized mini-computer which has the capability to be used as a desktop computer too. Recently, …

Why Not to Uninstall or Remove Python from Raspbian OS Read More »

Creating Your Python Virtual Environment

Working on a virtual environment can save your system and your works on it. Creating your Python virtual environment would ensure that the dependencies required for different projects are in separate environments. It is always recommended that you create a separate virtual environment for separate projects so that there are no clashes in dependencies requirements. …

Creating Your Python Virtual Environment Read More »