What is a function
A function is a named block of code that you can run as many times as you want. You have already used functions without knowing…
In this lesson, you will learn how to develop functions in Python programming. You will discover how to use and create various types of functions, from methods and functions with parameters to functions that return values. Enhance your skills through practical exercises and master the art of functions in programming.
A function is a named block of code that you can run as many times as you want. You have already used functions without knowing…
A function that always does the same is not very useful. With parameters, you can give it different data each time.
Until now functions showed things with print . The most usual thing, however, is for a function to calculate a result and return…
The exercises in the lesson follow a few patterns. We review them with an example function for each.
A variable created inside a function only exists inside it. Understanding where each variable lives avoids many mistakes.
The last two exercises of the lesson take the program away from the keyboard: they receive the data from the command line and…
These are the most frequent mistakes when starting with functions.
Writing a function that works is the first step; the second is that other people (and you in a month) can use it without reading…
Create a Python program that defines two functions: one to greet and another to say goodbye. Then, call both functions from the…
Create a Python program that defines two functions to greet and say goodbye. The exercise is similar to *Function greeting and…
Create a Python program that defines a function called change_letter() to modify a character of a text. The function receives as…
Create a Python program that defines the function is_alphabetic() to check whether a text entered by the user contains only…
Create a Python program with a function called is_number() that receives a text and determines whether it represents a number or…
Develop a Python program with a function called count_spaces that receives a text and returns the total number of spaces it…
Develop a Python program that asks the user for a number and stores it as text. Then, implement a function called sum_digits that…
Create a new version of the program *Calculator with command-line parameters* that finishes with the following exit codes:
Create a Python program with a function called write_centered_underlined that receives a text and displays it centered and…
Create a Python program with a function called find_min_max() that receives a list of real numbers and returns its minimum and…
Create a Python program that asks the user for 5 integers and stores them in a list. Then, implement a function called…
Create a Python program with a function called reverse_string that receives a text and returns it in reverse order.
Create a Python program with a function called is_palindrome() that checks whether a text is a palindrome. A palindrome is a text…
Create a Python program with a function called find_largest_value that receives a list of 5 real numbers requested from the user…
Create a Python program with a function called calculate_power() that calculates the result of raising an integer to the power of…
Create a Python program with a function called write_title_format() that writes a text centered on the screen, in uppercase, with…
A parameter can have a default value : if that argument is not given when calling the function, the default is used. Arguments…
A function can return several values at once: it actually returns a tuple, which can be unpacked into several variables when…
Functions are values: they can be stored in a dictionary, passed to another function and returned from a function. With that…