Working with Built-in Python Functions
Published by Lance Adhikari on July 7, 2025 · 10 min read
Built-in functions are a powerful part of Python. These are functions that are always available and can be used directly to perform common tasks like printing messages, checking data types, or sorting values. In this blog, we’ll explore useful built-in functions including print(), type(), min(), max(), and sorted(), and see how they apply to cybersecurity scenarios.
Using the print() Function
The print() function is used to output content to the screen. It takes one or more arguments and displays them, separated by spaces. This is useful for displaying results, error messages, or debugging information.
month = "September"
print("Investigate failed login attempts during", month, "if more than", 100)
Output: Investigate failed login attempts during September if more than 100
Understanding Data with type()
The type() function tells you the data type of a variable or value. This helps prevent errors when working with different types like strings, integers, or lists.
print(type("This is a string"))
Output: <class 'str'> – meaning the input is a string.
Combining Functions
You can pass the output of one function into another. In the example above, the output of type() was passed into print() to display the result. This is common practice and makes your code more dynamic.
Finding Values with max() and min()
The max() function returns the largest value from a group of numbers, while min() returns the smallest. This can help you detect anomalies or extremes in cybersecurity data.
time_list = [12, 2, 32, 19, 57, 22, 14]
print(min(time_list))
print(max(time_list))
Output: 2 and 57, representing the shortest and longest login sessions.
Organizing Data with sorted()
The sorted() function sorts a list or iterable in ascending order. It doesn’t change the original list but returns a new one. This is useful for organizing data like session durations or alert severity levels.
time_list = [12, 2, 32, 19, 57, 22, 14]
print(sorted(time_list))
print(time_list)
Output: [2, 12, 14, 19, 22, 32, 57] and the original list remains unchanged.
Important Note
The sorted() function only works with lists containing one data type. Mixing strings and numbers in the same list will result in an error.
Key Takeaways
Python’s built-in functions make coding easier and faster. Whether you’re printing output, checking types, finding maximums, or sorting data, these tools are especially helpful in cybersecurity for log analysis, anomaly detection, and automation.
Further Resources
Want to learn more? Check out the Python Standard Library documentation for a full list of built-in functions and how to use them.
Have questions or thoughts about built-in Python functions in cybersecurity? Reach out and connect—I’d love to hear from you!