Tag: python tutorials

Python Program to Convert Celsius To Fahrenheit

In this python program, we will learn how to convert celsuis to farenheit in python and display it using the print function. This program takes the input in celsius degree and then converts it to farenheit degree. The farenheit is usually calculated using the below formula farenheit = (celsius * 1.8) + 32 How to convert Celsius to Fahrenheit in Python? Output 34.0 Celsius =…

Recursive Functions in Python

This tutorial will teach you about Python recursive functions and how to use them to simplify your code. A recursive function is one that calls itself until it stops. The fn() function below is a recursive function because it calls itself: The #… in the fn() function denotes other code. A recursive function must also have a condition that causes it to stop calling itself….

Python Program to Check if a Number is Odd or Even

In this Python program, let’s learn how you can check a given number if it is odd or even. How to Check if a Number is Odd or Even in Python? A number is a even number if it is perfectly divisible by 2 i.e if the remainder is 0. In Python, you can use the modulus operator (%) to find the remainder. If the…

Comments in Python

This tutorial will teach you how to add comments to your code. You’ll also learn about different types of Python comments, such as block comments, inline comments, and documentation strings. You may want to document the code you write on occasion. You might wish to take note of why a piece of code works, for example. You use the comments to accomplish this. Formulas, algorithms,…

Functions in Python

In this tutorial, you will learn how to create Python functions using the def keyword. What is Function in Python? A named code block that performs a task or returns a value is referred to as a function. In some programs, you may need to repeat a task numerous times. You also don’t want to duplicate the code for the same task in several places….

Getting Started with Python

This tutorial will teach you what Python is and why you should start learning Python right away. Python is a cross-platform programming language, meaning it can operate on a variety of platforms including Windows, macOS, Linux, and the Java and.NET virtual machines. It’s completely free and open-source. Python boosts your efficiency. Python allows you to solve complicated issues with fewer lines of code and less…

Python Program to Find the Largest Value Among Three Numbers

This Python program shows you how you can use the conditional if else statement in Python to find the largest among three numbers and display the result. How to Find the Largest Value among three numbers in Python? Output The largest number among 3 Numbers is 65. In the above python program, the input numbers are stored in the variables number1,number2,number3 respectively. The conditional if…

Python Program to Find the Factorial of a Number

In this Python program, you will learn how to find the factorial of a number and display it using the print statement. Before we start coding, its important to understand what is a factorial. The factorial of a number is the product io all the number from 1 until that number. To give you an example , lets say you want to find the factorial…

Constants in Python

This tutorial will teach you how to define Python constants. Variables are useful for storing values. However, these values should not be changed during the program’s execution. You can use constants to accomplish this in different programming languages. Constants are similar to variables, except that their values do not change as the programme runs. Constants aren’t supported in Python, which is unfortunate. To get around…

Sort List in Python

In this article, you’ll learn how to sort a list with Python’s List sort() method. The sort() method is used to sort a list: The sort() method keeps the order of the original list. The sort() method changes the order of the elements in the list. The less-than operator () is used by default in the sort() method to sort the members of a list….

Lambda Expressions in Python

This tutorial will teach you about Python lambda expressions and how to use them to write anonymous functions. Sometimes you’ll need to write a single-expression function. This function, however, must only be used once. It will also be obsolete to use the def keyword to declare that function. Python lambda expressions are useful in this situation. What are Lambdas in Python? Anonymous functions can be…

Python Program to Convert Kilometers to Miles

This program demonstrates how you can convert kilometers to miles in Python. The conversion of Kilometer to miles is a kind of a simple calculation. The formula to calculate the mile from kilometers is below. 1 Mile = 1.60934 Kilometers. All that we need to do is do multiple the input (kilometers) by 0.621371 to get the total miles. How to Convert Kilometers to Miles…

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…