Sure thing! In Python, built-in functions are pre-defined functions that are included in the Python interpreter, so you can use them without having to declare or define them. These functions provide a wide range of functionality and are readily available for use in your programs.
Examples of Python Built-in Functions:
1. len():
- Returns the length (the number of items) of an object.
my_list = [1, 2, 3, 4, 5]
length = len(my_list)
print(length) # Output: 5
2. type():
- Returns the type of an object.
my_variable = 10
variable_type = type(my_variable)
print(variable_type) # Output: <class 'int'>
3. max() and min():
- Return the maximum or minimum value from a sequence.
numbers = [2, 8, 1, 6, 4]
max_value = max(numbers)
min_value = min(numbers)
print(max_value) # Output: 8
print(min_value) # Output: 1
4. sum():
- Returns the sum of all elements in a sequence.
numbers = [1, 2, 3, 4, 5]
total = sum(numbers)
print(total) # Output: 15
5. print():
- Outputs text to the console.
print("Hello, Python!") # Output: Hello, Python!
6. input():
- Reads a line from the console.
user_input = input("Enter your name: ")
print("Hello, " + user_input + "!")
These are just a few examples of the many built-in functions Python provides. They are designed to make common programming tasks easier and more convenient. Feel free to explore more in the Python documentation!