Tag: python tutorials
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…
Strings in Python
This tutorial will teach you how to use the Python string and its fundamental operations. A character string is a collection of characters. Anything inside quotations is a string in Python. You have the option of using single or double quotations. For instance: If a string contains a single quotation, it should be enclosed in double quotes, as shown below: You can also use single…
Variables in Python
This tutorial will teach you about Python variables and how to effectively use them. When creating a program, you must manage a large number of values. Variables are used to store values. A variable in Python is a label to which you can assign a value. And every variable has a value associated with it. As an example: Output Hello, World! Good Bye! The variable…
Boolean Data Type in Python
This tutorial will teach you about the Python boolean data type, as well as falsy and truthy values. In programming, you frequently want to check whether a condition is true or false and then take action based on the outcome. Python provides the boolean data type to represent true and false. The technical name for a boolean value is bool. True and False are the…
sorted() function in Python
In this lesson, you’ll learn how to sort a list using the Python sorted() method. The sort() method sorts a list at its current location. To put it another way, it rearranges the components in the original list. The sorted() function is used to return the new sorted list from the original list: The original list is not changed by the sorted() method. Using the…
Docstrings Functions in Python
This tutorial will teach you how to add documentation to a function using docstrings. Help() is a Python built-in function that displays a function’s documentation. The print() function documentation is demonstrated in the following example: The help() function can be used to display documentation for modules, classes, functions, and keywords. This tutorial only covers function documentation. Documenting functions with docstrings in Python You can use…
Comparison Operators in Python
This tutorial will teach you about Python comparison operators and how to use them to compare two values. In programming, you’ll frequently wish to compare one value to another. You use comparison operators to accomplish this. Python has six comparison operators: Less than ( < ) Less than or equal to (<=) Greater than (>) Greater than or equal to (>=) Equal to ( ==…
Keyword Arguments in Python
This tutorial will teach you about Python keyword arguments and how to use them to make function calls more visible. Let’s begin with a basic method for calculating the net price from the selling price and discount: The price and discount parameters are passed to the get net price() function. The following example explains how to use the get net price() function to get the…
Python Syntax
This lesson will teach you the fundamentals of Python syntax so you can get started quickly with the language. Whitespace and indentation If you’ve worked with other programming languages like Java, C#, or C/C++, you’re aware that semicolons (;) are used to separate statements. Python, on the other hand, constructs the code structure using whitespace and indentation. A piece of Python code is shown below:…
break statement in Python
This tutorial will teach you how to use the Python break statement to exit a loop prematurely. You may want to end a for loop or a while loop early regardless of the results of the conditional tests. In these cases, the break statement can be useful: To end a loop when a condition is True, you typically use the break statement in conjunction with…
Python Program to Generate Random Number
This program demonstrates how to generate random number in python using the randint method. How to generate random number in Python? Inorder to generate random number in Python, you will need to use the randint() function which is defined in the random module() in python. Output 7 Everytime when the randint function is called , it generates a different output as it is printed.
Python Program to Print Fibonacci Series
In this Python program, you will learn how to generate and print Fibonacci series using loops and conditional statements. What is a Fibonacci Sequence ? A Fibonacci sequence is an sequence of integers where the value of the sequence is determined by adding the preceding two values. The first two values in the sequence is 0 and 1. Then comes Next one with (N-1) +…
pass statement in Python
In this tutorial, you’ll learn how to use the Python pass statement as a placeholder. Consider the following if/else condition: You don’t have any code in the else clause yet. This else clause, however, will be coded later. If you run the code in this situation, you’ll get a syntax error (SyntaxError). The Python pass statement is useful in this situation: The statement pass has…
Numbers in Python
This tutorial will teach you about Python numbers and how to use them in your programs. Python various various data types like integers, floats, and complex numbers. This tutorial only covers integers and floats. Integers Integers are numbers with the type int, such as -1, 0, 1, 2, 3,… Math operators such as +, -, *, and / can be used to create expressions that…
while loop in Python
This tutorial will teach you how to utilise the Python while statement to run a code block as long as a condition is true. While in Python, if a condition is True, you can run a code block repeatedly. The Python while statement is shown in the following syntax: The condition is a boolean expression that returns True or False when evaluated. At the start…
Tuples in Python
This tutorial will teach you about Python tuples and how to use them effectively. You may want to make a list of elements that cannot be altered at any moment during the programme. Tuples make this possible. A tuple is a list that is immutable. Immutable is a Python term for a value that cannot change. A tuple is an immutable list by definition. How…
Type Conversion in Python
This tutorial will teach you about type conversion in Python as well as some useful type conversion functions. The input() function is used to obtain user input. As an example: When you run this code, the Terminal will prompt you for the following input: If you enter a value, such as a number, the programme will display that value back to you: The input() function,…