Python comes with a variety of built-in functions that can be used to perform common tasks. Here are some examples:

  • print(): This function is used to print output to the console.
print('Hello, world!')

 

  • len(): This function is used to get the length of a list, tuple, or string.

my_list = [1, 2, 3, 4, 5]

print(len(my_list))

 

  • range(): This function is used to create a sequence of numbers.

for i in range(10):

   print(i)

 

  • sum(): This function is used to get the sum of a list of numbers.

my_list = [1, 2, 3, 4, 5]

print(sum(my_list))

 

  • max(): This function is used to get the maximum value in a list of numbers.

my_list = [1, 2, 3, 4, 5]

print(max(my_list))

 

  • min(): This function is used to get the minimum value in a list of numbers.

my_list = [1, 2, 3, 4, 5]

print(min(my_list))

 

  • sorted(): This function is used to sort a list of numbers or strings.
my_list = [5, 4, 3, 2, 1]
print(sorted(my_list))
 
my_list = ['banana', 'apple', 'orange']
print(sorted(my_list))

 

  • zip(): This function is used to combine two or more lists into a list of tuples.
names = ['John', 'Jane', 'Mike']
ages = [30, 25, 35]
 
zipped = zip(names, ages)
print(list(zipped))

 

  • enumerate(): This function is used to iterate over a list and get the index of each element.
my_list = ['apple', 'banana', 'orange']
 
for i, fruit in enumerate(my_list):
    print(i, fruit)

 

  • map(): This function is used to apply a function to each element of a list.
my_list = [1, 2, 3, 4, 5]
 
def square(x):
    return x ** 2
 
squared = map(square, my_list)
print(list(squared))