0 votes
in Python Flask by

Can you name ten built-in functions in Python and explain each in brief?

1 Answer

0 votes
by
Ten Built-in Functions, you say? Okay, here you go.

complex()- Creates a complex number.

>>> complex(3.5,4)

(3.5+4j)

eval()- Parses a string as an expression.

>>> eval('print(max(22,22.0)-min(2,3))')

20

filter()- Filters in items for which the condition is true.

>>> list(filter(lambda x:x%2==0,[1,2,0,False]))

[2, 0, False]

format()- Lets us format a string.

>>> print("a={0} but b={1}".format(a,b))

a=2 but b=3

hash()- Returns the hash value of an object.

>>> hash(3.7)

644245917

hex()- Converts an integer to a hexadecimal.

>>> hex(14)

‘0xe’

input()- Reads and returns a line of string.

>>> input('Enter a number')

Enter a number7

‘7’

len()- Returns the length of an object.

>>> len('Ayushi')

6

locals()- Returns a dictionary of the current local symbol table.

>>> locals()

{‘__name__’: ‘__main__’, ‘__doc__’: None, ‘__package__’: None, ‘__loader__’: <class ‘_frozen_importlib.BuiltinImporter’>, ‘__spec__’: None, ‘__annotations__’: {}, ‘__builtins__’: <module ‘builtins’ (built-in)>, ‘a’: 2, ‘b’: 3}

open()- Opens a file.

>>> file=open('tabs.txt')
...