Author: admin
-
Python List
Summary: in this tutorial, you’ll learn about Python List type and how to manipulate list elements effectively. What is a List A list is an ordered collection of items. Python uses the square brackets ([]) to indicate a list. The following shows an empty list: Typically, a list contains one or more items. To separate…
-
Python Function Docstrings
Summary: in this tutorial, you’ll learn about how to use docstrings to add documentation to a function. Introduction to the help() function Python provides a built-in function called help() that allows you to show the documentation of a function. The following example shows the documentation of the print() function: Output: Note that you can use the help() function to show the documentation…
-
Python Lambda Expressions
Summary: in this tutorial, you’ll learn about Python lambda expressions and how to use them to write anonymous functions. Sometimes, you need to write a simple function that contains one expression. However, you need to use this function once. And it’ll unnecessary to define that function with the def keyword. That’s where the Python lambda expressions come into play.…
-
Python Recursive Functions
Summary: in this tutorial, you’ll learn about Python recursive functions and how to use them to simplify your code. Introduction to recursive functions A recursive function is a function that calls itself until it doesn’t. The following fn() function is a recursive function because it has a call to itself: In the fn() function, the #… means other code. Also, a recursive function…
-
Python Keyword Arguments
Summary: in this tutorial, you’ll learn about the Python keyword arguments, and how to use them to make function calls more obvious. Introduction to the Python keyword arguments Let’s start with a simple function that calculates the net price from the selling price and discount: The get_net_price() function has two parameters: price and discount. The following shows how to call the get_net_price() function to…
-
Python Default Parameters
Summary: in this tutorial, you’ll learn about the Python default parameters to simplify function calls. Introduction to Python default parameters When you define a function, you can specify a default value for each parameter. To specify default values for parameters, you use the following syntax: In this syntax, you specify default values (value2, value3, …) for each…
-
Python Functions
Summary: in this tutorial, you’ll learn to develop Python functions by using the def keyword. What is a function A function is a named code block that performs a job or returns a value. Why do you need functions in Python Sometimes, you need to perform a task multiple times in a program. And you don’t want…
-
Python pass
Summary: in this tutorial, you’ll learn how to use the Python pass statement as a placeholder. Introduction to the Python pass statement Suppose that you have the following if…else statement: In the else clause, you haven’t got any code yet. But you’ll write code for this else clause later. In this case, if you run the code, you’ll get a syntax error (SyntaxError).…
-
Python continue
Summary: in this tutorial, you’ll learn about the Python continue statement and how to use it to control the loop. Introduction to the Python continue statement The continue statement is used inside a for loop or a while loop. The continue statement skips the current iteration and starts the next one. Typically, you use the continue statement with an if statement to skip the current iteration once a condition is True.…
-
Python break
Summary: in this tutorial, you’ll learn about the Python break statement and how to use it to exit a loop prematurely. Introduction to the Python break statement Sometimes, you want to terminate a for loop or a while loop prematurely regardless of the results of the conditional tests. In these cases, you can use the break statement: Typically, you use the break statement with the if statement to terminate a…