Sitemap
Tehreem

Tehreem

Hey everyone! I'll be documenting my cybersecurity journey here. What I learn, what I understand. Feel free to reach out and tag along :)

Functions in Python

3 min readAug 24, 2026

--

Here I discuss functions in Python through code and problem statements as practiced in the Course 7: Automate Cybersecurity Tasks with Python. This lab is done in the Jupyter notebook.

1. Basic Alert Function:

Calling the alert() function that was defined earlier, that is how the statements inside the function are printed as an output.

Press enter or click to view image in full size

2. Repeating Alerts with a Loop:

Using for loop inside the function and then calling it, as long as the iteration remains, the same line will get printed as an output.

Press enter or click to view image in full size

3. Reading a List of Usernames:

Using a for loop inside a function to go through all the elements of the username_list and then print them.

Press enter or click to view image in full size

4. Combining Names into One Line:

Displaying the same list using the string concatenation using the + sign.

Press enter or click to view image in full size

5. Sorting Login Attempts:

Use of the built-in sorted() function to print the elements of the list in an ascending order.

Get Tehreem’s stories in your inbox

Join Medium for free to get updates from this writer.

Press enter or click to view image in full size

6. Finding the Worst-Case Number:

Use of the built-in max() function to print the maximum number of failed login attempts in a month.

Press enter or click to view image in full size

7. Passing Info into Functions:

Calling a function with parameters and arguments.

Press enter or click to view image in full size

8. Adding Baseline Averages:

Calculating an average of a user’s daily logins into a system.

Press enter or click to view image in full size

9. Doing Math with return:

Using the return statement instead can also be efficient.

Press enter or click to view image in full size

10. Triggering Conditional Alerts:

Creating an alert if number of logins from the same user is more than or equal to 3 because this demands an investigation.

Press enter or click to view image in full size

So, this was all about the functions in Python. I will see you in the next lab where I explore and learn more about the Python programming language and how to implement this logic into day-to-day SOC analyst tasks.

--

--

Tehreem
Tehreem

Written by Tehreem

Hey everyone! I'll be documenting my cybersecurity journey here. What I learn, what I understand. Feel free to reach out and tag along :)