for Loops in Python
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,…
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,…
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 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…
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".…
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…
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,…
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…
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…
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…
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…