4 Important Python Built-in Functions

4 Important Python Built-in Functions

These built-in functions that will help you save time.

Python Built-in Functions

  • Python provides a lot of built-in functions that ease the writing of code.

  • Built-in functions are predefined functions that are already available in Python.

• eval()

  • Python eval() function parse the expression argument and evaluate it as a python expression and runs python expression (code) within the program.

  • Let's say the math part is in string format, the eval() function helps to evaluate the mathematical calculation in the parse.

  • Syntax: eval(expression, globals=None, locals=None)

x="5*6"
y=eval(x)
print(y)

This will return 30.

• len()

  • Python len() function is an inbuilt function in Python. It can be used to find the length of an object.

  • Syntax: len(Object)

numbers=[10,52,8,34]
new_var = numbers
x=len(new_var)
print(x)

This will return 4.

• sorted()

  • Python sorted() function returns a sorted list from the iterable object.

  • Syntax: sorted(iterable, key, reverse)

numbers=[10,52,8,34]
new_var = numbers
x=sorted(new_var)
print(x)

This will return [8, 10, 34, 52].

• reversed()

  • Python reversed() method returns an iterator that accesses the given sequence in the reverse order.

  • Syntax: reversed(seq) #seq: sequence to be reversed.

a=['Python','Programming','Language']
x=reversed(a)

for i in x:
    print(i)

Which will return:

Language
Programming
Python

Hope you liked this article. Let me know your thoughts in the comments below. You can also link up with me on this platform and also on LinkedIn.