
PYTHON — Shout Message Python
Learning to write programs stretches your mind, and helps you think better, creates a way of thinking about things that I think is helpful in all domains. — Bill Gates
Shout the Message
In this lesson, we will be discussing how to use the string.shout() function. We will go through the process of passing a function call as an argument of another function and see how it works in Python.
Let’s begin by understanding the concept of passing a function call as an argument of another function. This can be achieved by passing string.shout() as an argument to the print() function.
Here’s the code to demonstrate this concept:
# main.py
import helpers.string as string
# Define variables
length = 5
width = 8
# Define the message
message = f"The area of a {length}-by-{width} rectangle is {string.shout(string)}"
# Print the message
print(message)In the code above, we import the string module from the helpers package. Then we define the variables length and width. Next, we create a message using an f-string where we format in the length and the width, and also the string.shout() function call. We then print the message.
The string.shout() function returns an uppercase string. This means that the message will be displayed in uppercase, as shown below:
THE AREA OF A 5-BY-8 RECTANGLE IS 40You can also modify the variables and rerun the code, as shown:
# Modify the length variable
length = 9
# Define the message
message = f"The area of a {length}-by-{width} rectangle is {string.shout(string)}"
# Print the message
print(message)When you run the above code, the output would be:
THE AREA OF A 9-BY-8 RECTANGLE IS 72As you can see, the message is now dynamically generated based on the modified variables.
Finally, to complete the solution, you can clean up the code by removing any unnecessary comments and ensuring proper formatting.
That’s a simple demonstration of passing a function call as an argument of another function in Python. This technique can be useful for creating dynamic and flexible code.
Did you find this explanation helpful? Let me know in the comments below.





