Category Python

for Loops in Python

spiral stairs

Loops are used when you need to repeat a block of code a certain number of times or apply the same logic over each item in a collection. There are two types of loops: for and while. In this article,…

Comments in Python

hash mark

The purpose of comments is to explain what is happening in the code. Comments are written along with your code but do not influence your program flow. When you work by yourself, maybe comments don’t feel like something you should…

Conditionals in Python

computer on desk

Conditionals are one of the cornerstones of any programming language. They allow you to control the program flow according to specific conditions you can check. The if statement The way you implement a conditional is through the if statement. The…

Booleans in Python

Computer screen with code

As far as data types go, the Boolean type is by far the simpler one. A boolean typed variable is either Trueor False. Notice the capitalization, that is how you should write these values in Python, not "true" or "false".…

Variables in Python

System of equations

In any program, you need to store and manipulate data to create a flow or some specific logic. That’s what variables are for. You can have a variable to store a name, another one to store the age of a…

Python Data Types

data

To store data in Python, you need some variable, and every variable has its type depending on the value of the data stored. Python has dynamic typing, which means you don’t have to explicitly declare the type of your variable,…

Python Lambda Functions

lambda

A Python lambda function can only have one expression and no multiple lines. It is supposed to make it easier to create some small logic in one line instead of a whole function as it is usually done. Lambda functions…

Command Line Arguments in Python

how to python

The best way to use command line arguments on your Python script is by using the argparse library. Step By Step First import the library import argparse The initialize a parser object parser = argparse.ArgumentParser(description='Find out the number of World…

File Handling in Python

The files

In this tutorial, I will show how to handle files in Python. Create, write, read, append and close files. File create First things first, create! We are going to use the open() function. This function opens a file and returns…

How to Split a String in Python

code on screen

Split a string into smaller parts is a very common task, to do so, we use the split() method in Python. Let’s see some examples on how to do that. Example 1: whitespaces as delimiters In this example, we split…