
PYTHON — Shout Function in Python
First, solve the problem. Then, write the code. — John Johnson
Adding a Shout Function in Python
In this tutorial, we’ll learn how to add a “shout” function to a Python module. The function will take a string as input and return a new string with all letters in uppercase. Let’s dive into the code and see how this can be implemented using Python.
Task List for Adding the Shout Function
First, let’s create a task list for adding the “shout” function to the string.py module.
- Add the Shout Function: Define a function called
shout()that takes a single string parameter and returns a new string with all letters in uppercase. - Define the Shout Function: Define the
shout()function with thepassstatement as a placeholder. - Specify the Parameter: Add a parameter named
stringto theshout()function to accept the input string to be shouted. - Return Uppercase String: Modify the function to return the input string in uppercase using the
.upper()method.
Implementation of the Shout Function
Let’s implement the “shout” function in the string.py module using the defined task list.
# string.py
def shout(string):
return string.upper()Testing the Shout Function
Now, let’s test the implemented shout() function by running the module and calling the function with a lowercase string.
# Testing the shout function
import string
shouted_string = string.shout("hello")
print(shouted_string) # Output: HELLOBy executing the above code, we can confirm that the shout() function successfully converts the input string to uppercase.
Conclusion
In this tutorial, we learned how to add a “shout” function to a Python module. The function takes a string as input and returns a new string with all letters in uppercase. This simple example demonstrates the implementation of a custom function within a Python module.





