Study smarter with Fiveable
Get study guides, practice questions, and cheatsheets for all your subjects. Join 500,000+ students with a 96% pass rate.
Python's built-in functions are the foundation of everything you'll write in this course. Whether you're processing user input, manipulating data structures, or debugging your code, these functions appear in virtually every program you'll create. Understanding when and why to use each function—not just what it does—separates students who struggle through assignments from those who code fluently.
You're being tested on your ability to choose the right tool for the job, convert between data types correctly, and work with collections efficiently. Don't just memorize syntax—know which functions handle input/output, which ones transform data types, which ones work with sequences, and which ones perform calculations. That conceptual framework will help you solve problems you've never seen before.
These functions handle communication between your program and the outside world. Every interactive program needs a way to receive data and display results.
sep parameter to customize the separatorend parameter controls what prints after your output; defaults to newline (\n) but can be changed for same-line printinginput("Enter your name: ")Compare: print() vs. input()—both handle console interaction, but print() sends data out while input() brings data in. Remember: input() always returns a string, so input("Number: ") + 1 will crash without conversion.
These functions transform data from one type to another. Python is dynamically typed, but operations often require specific types—conversion functions bridge that gap.
int(3.9) returns 3int("42"), essential for processing input() resultsint("hello") crashes your programfloat(5) returns 5.0, float("3.14") returns 3.14"Score: " + str(95) works; "Score: " + 95 crashesCompare: int() vs. float()—both convert to numbers, but int() discards decimals while float() preserves them. Choose based on whether your calculation needs decimal precision. For user input that could be either, float() is safer.
These functions help you understand what you're working with. Debugging and writing flexible code requires knowing your data types.
"5" + 5 fails, type() shows you one is <class 'str'>if type(x) == int:for i in range(len(my_list)): iterates through indicesCompare: type() vs. len()—both inspect objects, but type() tells you what kind of data you have while len() tells you how much. Use type() for debugging type errors; use len() for size validation and loop control.
These functions create Python's core collection types. Understanding when to use each structure is fundamental to organizing data effectively.
list("hello") returns ['h', 'e', 'l', 'l', 'o']dict(name="Alice", age=20) creates {'name': 'Alice', 'age': 20}range(start, stop, step) controls where to begin, end, and how to incrementrange(1, 5) produces 1, 2, 3, 4—not including 5Compare: list() vs. dict()—both store collections, but lists use numeric indices while dictionaries use custom keys. Use lists for ordered sequences; use dictionaries when you need to look up values by meaningful names (like student IDs or usernames).
These functions perform calculations on numbers and collections. They replace manual loops for common operations, making code cleaner and faster.
sum([1, 2, 3, 4]) returns 10sum([1, 2, 3], 10) returns 16 (adds 10 to the total)max(3, 7, 2) or max([3, 7, 2])max(words, key=len) finds the longest stringmax() with identical syntax optionsmin(students, key=lambda s: s['grade']) finds lowest grademax() to establish rangesabs(-7) returns 7abs(-3.14) returns 3.14Compare: max() vs. min()—identical syntax and behavior, just opposite results. Both accept the key parameter for custom comparisons. When finding both extremes, call them together: lowest, highest = min(data), max(data).
This function reorders sequences. Organizing data is fundamental to analysis and display.
.sort() methodsorted(nums, reverse=True) sorts in descending ordersorted(names, key=str.lower) ignores caseCompare: sorted() vs. list.sort()—sorted() creates a new list and works on any iterable, while .sort() modifies the original list in place and only works on lists. Use sorted() when you need to preserve the original order.
| Concept | Best Examples |
|---|---|
| Console I/O | print(), input() |
| String Conversion | str(), int(), float() |
| Type Inspection | type(), len() |
| Collection Constructors | list(), dict(), range() |
| Aggregation | sum(), max(), min() |
| Sorting | sorted() |
| Mathematical | abs(), sum() |
| Loop Control | range(), len() |
Which two functions would you use together to get a number from the user and use it in a calculation? Why is using just input() insufficient?
You have a list of test scores and need to find the range (difference between highest and lowest). Which built-in functions would you combine to calculate this?
Compare list() and dict()—when would you choose one over the other for storing student information?
Your code crashes with "can only concatenate str (not 'int') to str." Which built-in function would you use to fix this, and where would you apply it?
Explain the difference between sorted(my_list) and my_list.sort(). In what situation would choosing the wrong one cause a bug in your program?