Built-in Functions
Built-in functions in Python are predefined functions that are readily available for use in any Python program without requiring additional specifications or definitions. One of these built-in functions is the print()
function, which we have already used. We didn't need to define this function, write its body, or specify the return value; we simply called it and provided inputs. There are many built-in functions in Python. Let's consider some of the most commonly used ones:
print()
: Outputs a specified message or variable to the console.
1print("My message")
len()
: Returns the number of elements in an object, such as a string, list, or tuple.
12word = "Codefinity" print("Word length:", len(word))
sum()
: Computes the total of a sequence of numbers.
12numbers = [5, 2, 3] print("Sum of numbers:", sum(numbers))
max()
and min()
: Return the maximum or minimum value from a sequence.
123numbers = [5, 2, 3] print("The largest among the numbers:", max(numbers)) print("The smallest of the numbers:", min(numbers))
You might already be familiar with these functions, or perhaps not. The key in this chapter is to understand the difference between built-in functions and those you create yourself.
Tak for dine kommentarer!
Spørg AI
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat