10 commonly used built-in functions

In Python, built-in functions are pre-defined functions that are available for you to use without needing to write the code for them yourself. These functions are built into the Python language and perform common tasks and operations, making your coding life easier.

Here are 10 examples of the most commonly used built-in functions in Python:

  1. print(): Displays output on the console. You can pass values or variables as arguments to the print() function.
    print("Hello, world!")  # Output: Hello, world!
  2. len(): Returns the length of a string, list, or any other iterable object.
    fruits = ["apple", "banana", "orange"]
    print(len(fruits))  # Output: 3
  3. input(): Gets user input from the console. It displays a prompt and waits for the user to enter a value.
    name = input("Enter your name: ")
    print("Hello, " + name + "!")  # Output: Hello, [user's name]!
  4. type(): Determines the type of an object. It returns the type as a string.
    x = 5
    print(type(x))  # Output: <class 'int'>
  5. max(): Returns the largest item in an iterable or the largest of two or more arguments.
    numbers = [10, 5, 8, 12]
    print(max(numbers))  # Output: 12
  6. min(): Returns the smallest item in an iterable or the smallest of two or more arguments.
    numbers = [10, 5, 8, 12]
    print(min(numbers))  # Output: 5
  7. sum(): Returns the sum of all items in an iterable.
    numbers = [1, 2, 3, 4, 5]
    print(sum(numbers))  # Output: 15
  8. round(): Rounds a number to a specified number of decimal places.
    x = 3.14159
    print(round(x, 2))  # Output: 3.14
  9. str(): Converts an object into a string.
    x = 10
    print("The value is " + str(x))  # Output: The value is 10
  10. sorted(): Returns a new sorted list from the items in an iterable.
    numbers = [5, 2, 8, 1, 9]
    sorted_numbers = sorted(numbers)
    print(sorted_numbers)  # Output: [1, 2, 5, 8, 9]

These examples demonstrate the usage of various built-in functions in Python. Remember, there are many more built-in functions available, each serving a specific purpose. You can explore the Python documentation to learn more about them.