Lesson: The 10 Python Functions You've Used 1,000 Times
š Full written solution: https://interview-kit-fe.vercel.app/top-10-python-built-in-functions-every-developer-should-know š» Code on GitHub: https://github.com/timepasshub2539-hue/leetcode-python/tree/main/top-10-python-built-in-functions-every-developer-should-know Chapters: 0:00 You've Used These 10 Functions Thousands of Times 0:14 What Do We Mean By Built-in 0:31 1. print ā Show Something 0:43 2. len ā Measure Size 0:58 3. range ā Generate Numbers 1:12 4. type ā Ask What Something Is 1:30 5. input ā Ask the User Something 1:45 6. sorted ā Put Things in Order 2:02 7. Turn a List Into One Number 2:17 8. str, int, float ā Convert Types 2:34 Common Mistake: Forgetting to Convert 2:52 len vs sum ā Don't Confuse Them 3:06 My Honest Take 3:24 Recap: The Ten to Remember You call print(), len(), and range() constantly ā but do you know what they're really doing under the hood? This lesson walks through the 10 built-in Python functions every developer relies on daily: print, len, range, type, input, sorted, sum, and the str/int/float converters. We also cover the classic mistake of forgetting to convert input(), and clear up the len vs sum mix-up for good. #python #pythonforbeginners #learnpython #coding #programmingbasics Watch next: - Your AI Agent Is Wrong Right Now And Doesn't Know It #shorts: https://youtu.be/fUT9hmg4iA0 - Your AI Agent Is Wrong Right Now And Doesn't Know It #shorts: https://youtu.be/lESqqansVtI - Lesson 11: Why Does return None Happen to Everyone?: https://youtu.be/uTHuP6xhP5M
Introduction
Every Python developer, whether they've written ten scripts or ten thousand, leans on the same small set of built-in functions constantly. print(), len(), range() ā these show up so often that most people stop thinking about what they actually do. That's a problem, because interviewers do think about it. A candidate who can't explain why input() returns a string, or why sorted() doesn't touch the original list, signals a shaky mental model ā even if they can solve a medium-difficulty LeetCode problem.
This lesson isn't about memorizing syntax. It's about understanding the ten built-in functions that form the actual foundation of everyday Python: print, len, range, type, input, sorted, sum, max, and the trio of converters str, int, and float. Get these solid, and a huge chunk of "why is my code broken" confusion disappears. This is also exactly the kind of fundamentals check that shows up early in technical interviews ā not as a standalone question, but as the invisible scaffolding underneath everything else you're asked to build.
Problem Overview
There's no LeetCode-style problem statement here ā this is a fundamentals lesson. But it's worth framing it like one, because the underlying skill being tested is identical to what interviewers probe for: do you understand what your tools actually do, or are you just pattern-matching syntax you've memorized?
The "problem" is this: Python ships with a set of functions available in every file, with no import required. These are called built-in functions. Knowing which one to reach for ā and what type it hands back ā is the difference between code that flows naturally and code where you're constantly fighting TypeErrors and off-by-one bugs.
We'll group them into four categories:
- Inspecting values:
print,type,len - Generating sequences:
range - Talking to the user:
input - Working with collections:
sorted,sum,max - Converting between types:
str,int,float
Example
print("Hello") # Hello
len("cat") # 3
list(range(3)) # [0, 1, 2]
type(5) # <class 'int'>
type("hi") # <class 'str'>
sorted([5, 1, 4]) # [1, 4, 5]
sum([5, 1, 4]) # 10
max([5, 1, 4]) # 5
int("5") + int("3") # 8
Walking through the outputs:
len("cat")returns3because it counts the characters in the string ā not the value of anything, just the count of items.list(range(3))produces[0, 1, 2]ā three numbers starting at zero, becauserangeis zero-indexed by default and stops before the number you give it.sorted([5, 1, 4])returns a new list,[1, 4, 5]. The original list passed in is untouched.sum([5, 1, 4])adds everything together and collapses the list into a single number,10.max([5, 1, 4])does the same collapsing, but keeps only the largest value,5.int("5") + int("3")equals8because both strings were converted to integers before the addition. Skip the conversion and"5" + "3"gives you"53"ā string concatenation, not arithmetic.
Intuition
Here's how an experienced developer actually thinks about built-ins ā not as a list to memorize, but as answers to recurring questions your code asks.
Every program needs to do a small number of things repeatedly: show me what's happening (print), tell me how big this is (len), give me a sequence of numbers (range), tell me what kind of thing this is (type), get input from a person (input), and organize or summarize a collection (sorted, sum, max). Python's designers noticed these needs are so universal that making developers import a module or write a helper function for each one would be needless friction. So they became built-in ā always available, no import needed.
The mental model that clicks for most people: built-ins are the utensil drawer in your kitchen. You don't buy a spoon every time you need one ā it's just there. Same with len(). You don't write a loop to count characters ā it's already in your hand.
The one concept that trips up nearly everyone starting out is type. Python doesn't automatically know that the text "5" you typed at a keyboard prompt means the number 5. To Python, it's just a string of characters until you explicitly say otherwise. That single fact explains almost every "why doesn't my code work" question a beginner has about input().
Brute Force Solution
There isn't really a "brute force" version of using a built-in function ā but there is a brute-force version of what these functions save you from writing yourself. Consider sum():
def my_sum(numbers):
total = 0
for n in numbers:
total += n
return total
Idea: manually loop through the collection and accumulate a result.
Algorithm: initialize an accumulator, iterate once, update the accumulator on each step, return it.
Advantages: transparent ā you can see exactly what's happening, and it's a useful exercise for understanding how sum() works internally.
Disadvantages: more code to maintain, more room for bugs (forgetting to initialize total, off-by-one errors), and it reinvents something the language already gives you for free.
Time complexity: O(n) ā same as the built-in. Space complexity: O(1) ā same as the built-in.
The built-in sum() does the identical work, just implemented in C under the hood, which makes it faster and ā more importantly ā impossible to get wrong.
Optimal Solution
The "optimal solution" here is simply: use the built-in. Each one is doing meaningful work under the hood, and understanding what that work is makes you faster at reading and writing code.
| Function | What it does | Returns |
|---|---|---|
print(x) |
Displays a value on screen | None |
len(x) |
Counts items in a sequence | int |
range(n) |
Generates a sequence of numbers | range object (iterable) |
type(x) |
Reports the category of a value | type |
input(prompt) |
Pauses and waits for user text | str (always) |
sorted(x) |
Returns a new sorted copy | list |
sum(x) |
Adds all items together | int/float |
max(x) |
Returns the largest item | matches item type |
str(x), int(x), float(x) |
Converts between types | matches target type |
The one detail worth burning into memory: input() always returns a string, no matter what the user typed. If you need a number, you convert it ā every time, no exceptions.
age = input("How old are you? ") # age is a string, e.g. "25"
age = int(age) # now age is 25, an integer
And the classic mix-up worth locking in: len() tells you how many items are in a collection. sum() tells you what they add up to. They sound similar and solve completely different problems ā pause and ask yourself which one you actually need.
Python Code
def demo_built_ins() -> None:
"""Show each of the ten core built-in functions in action."""
# print ā display output
print("Hello, Python!")
# len ā measure size
word = "cat"
print(len(word)) # 3
# range ā generate a sequence
numbers = list(range(3))
print(numbers) # [0, 1, 2]
# type ā inspect category
print(type(5)) # <class 'int'>
print(type("hi")) # <class 'str'>
# input ā get user text (always returns str)
raw = input("Enter a number: ")
value = int(raw) # must convert before doing math
print(value + 1)
# sorted ā organize without mutating the original
messy = [5, 1, 4]
print(sorted(messy)) # [1, 4, 5]
print(messy) # [5, 1, 4] ā unchanged
# sum and max ā collapse a list to one value
print(sum(messy)) # 10
print(max(messy)) # 5
# str, int, float ā convert between types
print(int("5") + int("3")) # 8, not "53"
print(float("3.14")) # 3.14
print(str(42) + " items") # "42 items"
if __name__ == "__main__":
demo_built_ins()
Code Walkthrough
print("Hello, Python!")ā sends text to the console. It returnsNone; it's a side effect, not a value you use downstream.len(word)ā counts the characters in the string"cat", returning3as anint.list(range(3))ārange(3)produces a lazy sequence of0, 1, 2; wrapping it inlist()forces it into a concrete list so we can print it directly.type(5)/type("hi")ā returns the class of the object, letting you checkintvsstrbefore you act on a value.input("Enter a number: ")ā pauses execution, waits for the user, and returns whatever they typed as astr, regardless of content.int(raw)ā explicitly converts that string to an integer. Skip this step andvalue + 1throws aTypeError, because you can't add an integer to text.sorted(messy)ā builds and returns a new list in ascending order.messyitself is never modified ā you can verify this by printing it again afterward.sum(messy)/max(messy)ā both walk the list once, butsumaccumulates a running total whilemaxtracks the largest value seen.int("5") + int("3")ā each string is converted to an integer before the+operator runs, so this performs arithmetic (8) instead of string concatenation ("53").str(42) + " items"ā converts the integer42to"42"so it can be concatenated with another string.
Dry Run
Take the input-conversion line: age = input("How old are you? ") followed by age = int(age).
- Python displays
"How old are you? "and pauses. - The user types
25and presses enter. input()returns the string"25"ā note the quotes; it is text, not a number.agenow holds"25"(typestr).int(age)reads the string, parses it as a whole number, and returns25(typeint).ageis reassigned to25ā now safe to use in arithmetic likeage + 1, which evaluates to26.
Skip step 5, and age + 1 raises TypeError: can only concatenate str (not "int") to str ā the exact mistake almost every beginner hits in their first month.
Complexity Analysis
len(): O(1) for lists and strings ā Python stores the length as metadata, it doesn't count elements each time.range(n): O(1) to create (it's lazy), O(n) to fully iterate or materialize into a list.sorted(): O(n log n) time, since it uses Timsort under the hood; O(n) space for the new list it builds.sum()/max(): O(n) time ā each must look at every element once; O(1) space, since they only track a running accumulator.type(),str(),int(),float(): O(1) for typical scalar conversions.
These are correct because none of these operations require more information than a single pass over the input (or, for len, no pass at all ā just a stored count).
Alternative Solutions
For sorted() specifically, Python also offers list.sort(), which sorts in place and returns None instead of returning a new list. Use sorted() when you need to preserve the original order elsewhere in your program; use .sort() when you don't need the original and want to avoid the memory overhead of a second list.
messy = [5, 1, 4]
messy.sort() # mutates messy directly, returns None
There's no real alternative to len, range, type, or the converters ā they're thin, direct operations with no meaningful competing approach.
Edge Cases
- Empty input:
len([])returns0,sum([])returns0, butmax([])raisesValueError: max() arg is an empty sequenceā max needs at least one item to compare. - Duplicates:
sorted([3, 1, 3, 2])handles duplicates fine, returning[1, 2, 3, 3]ā no special casing needed. - Non-numeric input to
int():int("abc")raisesValueError. Always validate or wrap in atry/exceptwhen converting untrusted user input. - Negative or zero
range():range(0)produces an empty sequence;range(-3)also produces an empty sequence unless you supply a negative step. - Mixed types in
sorted()orsum(): sorting or summing a list with bothintandstrvalues raisesTypeErrorā Python won't guess how to compare or add across types.
Common Mistakes
- Forgetting
input()returns a string and trying to do math on it directly, causing aTypeError. - Confusing
len()andsum()ā asking "how many" when you meant "what's the total," or vice versa. - Assuming
sorted()mutates the original list ā it doesn't; you have to reassign the result if you want to keep it. - Calling
max()on an empty collection without a default, causing an unhandledValueError. - Concatenating instead of converting ā writing
"Total: " + 5instead of"Total: " + str(5), which raisesTypeError: can only concatenate str (not "int") to str. - Overusing
print()for debugging in larger projects instead of learning a proper debugger ā fine for a ten-line script, painful in a codebase with real depth.
Interview Questions
- What's the time complexity of
len()on a Python list, and why is it O(1) instead of O(n)? - What does
sorted()return versuslist.sort(), and when would you choose one over the other? - Why does
input()always return a string, and what's the risk of skipping conversion? - How would you safely convert user input to an integer without crashing on bad data?
- What's the difference between
range(5)andlist(range(5))in terms of what's actually created in memory?
Similar Problems
- Two Sum (LeetCode 1) ā relies on understanding iteration and collection lookups, the same fundamentals
sum/maxbuild toward. - Valid Anagram (LeetCode 242) ā a natural next step using
sorted()to compare character arrangements. - Contains Duplicate (LeetCode 217) ā leans on
len()and set conversion, reinforcing the "how big is this collection" instinct. - Merge Sorted Array (LeetCode 88) ā deepens the intuition behind what
sorted()is actually doing internally.
Key Takeaways
Built-in functions aren't training wheels ā they're the actual tools professional Python developers use every day. print shows you what's happening. len measures. range generates. type and input inspect and ask. sorted, sum, and max summarize collections without a manual loop. str, int, and float convert between forms without changing meaning. Master these ten, and most everyday Python code stops feeling mysterious ā freeing up your attention for the actual problem you're solving instead of fighting the language.
Watch the Video
For the full walkthrough with live examples and the input-conversion mistake explained in real time, watch the video here: {LINK}
About the Series
This lesson is part of the Daily Python LeetCode series ā short, focused breakdowns of Python fundamentals and interview-style problems, built for developers who want to strengthen their core skills one concept at a time, without wading through hour-long tutorials.
Call To Action
If this cleared something up, hit like on the video ā it genuinely helps the channel reach more developers. Subscribe on YouTube so you don't miss the next lesson, and subscribe to the Substack newsletter for the written breakdown delivered straight to your inbox. Drop a comment with which built-in function trips you up most, and share this with a teammate who's still debugging their first TypeError.
The solution
int("5") + int("3") # 8
str(8) # "8"Ready to try it yourself? Solve General problems with instant feedback in the practice sandbox.
Practice now ā


