What Built-ins Are
In this tutorial, we'll understand functions Python gives you automatically.
Built-in functions are functions Python gives you automatically.
You do not need to install or import anything to use them:
print("Hello")
len("Python")
type(42)
They are always available in normal Python code.
Why Built-ins Matter
Built-ins solve common tasks:
- Show output with
print() - Get input with
input() - Count items with
len() - Convert values with
int(),float(), andstr() - Sort values with
sorted() - Add numbers with
sum()
Instead of writing these tools yourself, you use the versions Python already provides.
Functions vs Methods
A function is called by name:
len("hello")
A method is attached to a value:
"hello".upper()
Both do useful work, but they are called differently.
Built-ins Are Not Magic
You still need to understand what each function expects.
int("42") # works
int("hello") # error
int() can convert text that looks like a whole number. It cannot convert any text.
Finding Help
Python has many built-ins, but you do not need to memorise them all. Learn the common ones first, then look up others when you need them.
You can also experiment in the Python shell:
>>> len("hello")
5
>>> max([3, 9, 1])
9
Practice
Use print(), len(), and type() on three different values.