Python while Loop

Python while loop is used to repeat a block of code until the specified condition is False. The while loop is used when we don’t know the number of times the code block has to execute. We should take proper care in writing while loop condition if the condition never returns False, the while loop …

Python while Loop Read More »

Python for Loop

Python for loop is used to iterate over a sequence of items. The for loop is implemented using the reserved keyword – for. The for-loop code is executed for each element of the sequence. We can get out of the for loop using the break statement. We can use continue statement to skip the execution …

Python for Loop Read More »

Python if else elif Statement

Python if-elif-else statement is used to write a conditional flow code. The statements are in the order of if…elif…else. The ‘elif’ is short for ‘else if’ statement. It’s shortened to reduce excessive indentation. The else and elif statements are optional. There can be multiple elif statements. We can have only one else block for an …

Python if else elif Statement Read More »

Python return Statement

The python return statement is used in a function to return something to the caller program. We can use the return statement inside a function only. In Python, every function returns something. If there are no return statements, then it returns None. If the return statement contains an expression, it’s evaluated first and then the …

Python return Statement Read More »

Python Functions

A function is a block of code with a name. We can call a function by its name. The code inside a function only runs when it’s called. A function can accept data from the caller program, it’s called as function parameters. The function parameters are inside parentheses and separated by a comma. A function …

Python Functions Read More »

Python Operators

Operators are used to performing a specific operation on variables and values. Python has a lot of operators that are either keywords or special characters. The values or variables on which these operators work are called operands. Types of Python Operators Python operators can be classified into the following categories. Arithmetic Operators Logical Operators Comparison …

Python Operators Read More »

Python Data Types

Python is an object-oriented programming language. Every variable in Python is an instance of some class. There are many pre-defined data types in Python. We can create our own classes to define custom data types. What are the Popular Data Types in Python? Some of the popular data types in Python are: Numbers – int, …

Python Data Types Read More »

Python Indentation

Indentation in Python is used to create a group of statements. Many popular languages such as C, and Java uses braces ({ }) to define a block of code, Python use indentation. How Does Python Indentation work? When writing python code, we have to define a group of statements for functions and loops. This is …

Python Indentation Read More »

Python Statements – Multiline, Simple, and Compound Examples

Python statements are the code instructions that are executed by the Python interpreter. Python Statements Examples Let’s look at some simple statement examples. Python Multi-line Statements Python statements are usually written in a single line. The newline character marks the end of the statement. If the statement is very long, we can explicitly divide into …

Python Statements – Multiline, Simple, and Compound Examples Read More »