Tag: python tutorials
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…