Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Built-in Functions | What is a Function in Python?
Python Functions Tutorial

book
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.

print("My message")
1
print("My message")
copy

len(): Returns the number of elements in an object, such as a string, list, or tuple.

word = "Codefinity"
print("Word length:", len(word))
12
word = "Codefinity" print("Word length:", len(word))
copy

sum(): Computes the total of a sequence of numbers.

numbers = [5, 2, 3]
print("Sum of numbers:", sum(numbers))
12
numbers = [5, 2, 3] print("Sum of numbers:", sum(numbers))
copy

max() and min(): Return the maximum or minimum value from a sequence.

numbers = [5, 2, 3]
print("The largest among the numbers:", max(numbers))
print("The smallest of the numbers:", min(numbers))
123
numbers = [5, 2, 3] print("The largest among the numbers:", max(numbers)) print("The smallest of the numbers:", min(numbers))
copy

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.

question mark

Which of the following best describes the difference between built-in functions and your own functions?

Select the correct answer

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 6

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

some-alt