Python has many built-in functions that perform various tasks. Here are some commonly used ones:
-
len(): Returns the length of an object (like a string, list, or tuple).length = len("Hello") # Returns 5 -
type(): Returns the type of an object.obj_type = type(5) # Returns <class 'int'> -
str(): Converts an object to a string.string_value = str(100) # Returns '100' -
int(): Converts a value to an integer.integer_value = int("10") # Returns 10 -
float(): Converts a value to a float.float_value = float("3.14") # Returns 3.14 -
sorted(): Returns a sorted list from the specified iterable.sorted_list = sorted([3, 1, 2]) # Returns [1, 2, 3] -
sum(): Returns the sum of all items in an iterable.total = sum([1, 2, 3]) # Returns 6 -
max(): Returns the largest item in an iterable.largest = max([1, 2, 3]) # Returns 3 -
min(): Returns the smallest item in an iterable.smallest = min([1, 2, 3]) # Returns 1 -
input(): Allows user input from the console.user_input = input("Enter your name: ") # Prompts user for input
These functions are just a starting point. Python has many more built-in functions that can help you perform various tasks efficiently. If you want to learn more about a specific function or topic, let me know!
