Tag: python tutorials

continue statement in Python

This tutorial will teach you about the Python continue statement and how to use it to control the loop. Within a for loop or a while loop, the continue statement is used. The continue statement terminates the current iteration and begins the next. When a condition is True, you typically use the continue statement in conjunction with an if statement to skip the current iteration….

Python Program to Check If a Given Year is Leap Year

This Python program will demonstrate how you can check to see if a given year is a leap year or not. A leap year is a year that is exactly divisible by 4 except for the years that end with 00. For the years that ends with 00 , it is considered to be a leap year if it is divisible by 400. How to…

if statement in Python

You’ll learn how to utilise the Python if statement to run a block of code based on a condition in this article. The if statement is used to execute a block of code based on a condition. The if statement has the following syntax: The condition is checked first by the if statement. If the condition evaluates to True, the if-block statements are executed. Otherwise,…

Python Program to Print Prime Numbers in a Given Interval

This Python program explains how you can print prime numbers in a given interval in python using loops. A number is a prime number if the following conditions are satisfied It is a Positive Number It is Greater than 1. Has no other factors except 1 and the number itself. Some of the examples of a prime number are 2,3 etc. How to Print Prime…

Logical Operators in Python

This tutorial will teach you about Python logical operators and how to use them to combine multiple conditions. You might want to verify several conditions at once. Use logical operators to accomplish this. The logical operators in Python are as follows: andornot and operator in Python The and operator determines if two conditions are True at the same time: If both conditions are true, it…

List in Python

This tutorial will teach you about the Python List type and how to effectively manipulate list elements. What is a List? A list is an ordered grouping of items. Python indicates a list with square brackets ([]). The following is an example of an empty list: A list typically contains one or more items. A comma is used to separate two items (,). As an…

for Loop with Range in Python

This article will teach you how to use the Python for loop to execute a code block a set number of times. In programming, it’s common to wish to run a block of code several times. A for loop is used to accomplish this. The syntax of a for loop is illustrated below: The index is referred to as a loop counter in this form….

Python Program to Swap Two Variables

In this Python program , you will learn how to swap two variables easily with 2 options. Swap two variable using a temporary variable in python. Swap two variable without using temporary variable in python. How to Swap two variables in Python without using Temporary Variable? Output a : 3b : 8 How to Swap Two variables without using Temporary variable in Python? There are…

Default Parameters in Python

This tutorial will teach you how to use Python’s default parameters to make function calls easier. You can give a default value for each argument when you define a function. The following syntax is used to specify default values for parameters: The assignment operator (=) is used to specify default values (value2, value3,…) for each parameter in this syntax. When you call a function and…

Python Program to Generate Multiplication Table

In this Python program, you will learn how to use loops in python to generate and display multiplication table of a given number. How to Generate and Display Multiplication Table in Python? Output 8 x 1 = 88 x 2 = 168 x 3 = 248 x 4 = 328 x 5 = 408 x 6 = 488 x 7 = 568 x 8 =…

Python Program to Check if a Number is Positive, Negative or Zero

In this python program, you’l learn how to check for a number of it is a positive , negative or zero. We will be using the conditional statements in python to solve this problem. How to find if a number is positive, negative or zero? Output The number that you entered is a Positive number A number is considered to be positive if it is…

Ternary Operator in Python

This tutorial will teach you about the Python ternary operator and how to use it to make your code more concise. The following program asks for your age and then calculates the ticket price: Here’s what happens if you type 18: If the age is more than or equal to 18, the following if…else line assigns 20 to the ticket price. Otherwise, the ticket price…