0% found this document useful (0 votes)
2 views6 pages

Inbuilt Functions - Notes

The document provides an overview of various inbuilt functions in Python, detailing their purpose and usage. Functions covered include abs(), all(), any(), bin(), bool(), sum(), eval(), float(), complex(), min(), max(), hex(), oct(), sorted(), input(), int(), pow(), range(), reversed(), round(), and type(). Each function is explained with examples demonstrating how to implement them in Python code.

Uploaded by

Kishan Jaycker
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

Inbuilt Functions - Notes

The document provides an overview of various inbuilt functions in Python, detailing their purpose and usage. Functions covered include abs(), all(), any(), bin(), bool(), sum(), eval(), float(), complex(), min(), max(), hex(), oct(), sorted(), input(), int(), pow(), range(), reversed(), round(), and type(). Each function is explained with examples demonstrating how to implement them in Python code.

Uploaded by

Kishan Jaycker
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Inbuilt Functions - Notes

Topics Covered:
● Inbuilt Functions
○ abs() Function:
○ all() Function:
○ any() Function:
○ bin() Function:
○ bool() Function:
○ sum() Function:
○ eval() Function:
○ float() Function:
○ complex() function:
○ min() Function:
○ max() Function:
○ hex() Function:
○ oct() Function:
○ sorted() Function:
○ input() Function:
○ int() Function:
○ pow() Function:
○ range() Function:
○ reversed() Function
○ round() Function:
○ type() Function:

Inbuilt Functions
Functions that are built into Python and readily available for use are known as Inbuilt Functions.

abs() Function:
Return the absolute value of a number.

x = abs(-7.25)
print(x)

1
all() Function:
Check if all items in a list are True

mylist = [True, True, True]


x = all(mylist)
print(x)

any() Function:
Returns True if any item in an iterable object is true

mylist = [False, True, False]


x = any(mylist)
print(x)

bin() Function:
Returns the binary version of a number

x = 10
y = bin(x)
print (y)

bool() Function:
Returns the boolean value of the specified object

# Returns False as x is False


x = False
print(bool(x))

# Returns True as x is True


x = True
print(bool(x))

sum() Function:
Sum() function is used to get the sum of numbers of an iterable, i.e., list.

s = sum([1, 2,4 ])
print(s)
s = sum([1, 2, 4], 10)
print(s)

2
eval() Function:
The function parses the expression passed to it and runs python expression(code)
within the program.

x=8
print(eval('x*2'))

float() Function:
The function returns a floating-point number from a number.

# for integers
print(float(9))

# for floats
print(float(8.19))

# for string floats


print(float("-24.27"))

# for string floats with whitespaces


print(float(" -17.19\n"))

complex() function:
It is used to convert numbers or strings into a complex number. This method takes two
optional parameters and returns a complex number. The first parameter is called a real
and second as imaginary parts.

a = complex(1) # Passing single parameter


b = complex(1,2) # Passing both parameters
# Displaying result
print(a)
print(b)

min() Function:
Returns the smallest item

small = min(2225,325,2025) # returns smallest element


print(small)

3
max() Function:
Returns the largest item

large = max(2225,325,2025) # returns largest element


print(large)

hex() Function:
It is used to generate the hex value of an integer argument. It takes an integer argument
and returns an integer converted into a hexadecimal string.

result = hex(1)
print(result)

oct() Function:
Converts a number into an octal

val = oct(10)
print(val)

sorted() Function:
Returns a sorted list

str = "python" # declaring string


sorted1 = sorted(str, reverse=True) # sorting string
print(sorted1)

input() Function:
It is used to get input from the user. It prompts for the user input and reads a line. After
reading data, it converts it into a string and returns it. It throws an error EOFError if EOF
is read.

val = input("Enter a value: ")


print("You entered:",val)

4
int() Function:
Python int() function is used to get an integer value. It returns an expression converted
into an integer number.
● If the argument is a floating-point, the conversion truncates the number.
● If the argument is outside the integer range, then it converts the number into a
long type.
● If the number is not a number or if a base is given, the number must be a string.

val = int(10) # integer value


val2 = int(10.52) # float value
val3 = int('10') # string value
print("integer values :",val, val2, val3)

pow() Function:
The python pow() function is used to compute the power of a number.
It returns x to the power of y. If the third argument(z) is given, it returns x to the power of
y modulus z, i.e. (x, y) % z.
# positive x, positive y (x**y)
print(pow(4, 2))

# negative x, positive y
print(pow(-4, 2))

# positive x, negative y (x**-y)


print(pow(4, -2))

# negative x, negative y
print(pow(-4, -2))

range() Function:
Returns a sequence of numbers, starting from 0 and increments by 1 (by default)

# empty range
print(list(range(0)))

# using the range(stop)


print(list(range(4)))

# using the range(start, stop)


print(list(range(1,7 )))

5
reversed() Function:
Returns a reversed iterator

# for string
String = 'Java'
print(list(reversed(String)))

# for tuple
Tuple = ('J', 'a', 'v', 'a')
print(list(reversed(Tuple)))

# for range
Range = range(8, 12)
print(list(reversed(Range)))

# for list
List = [1, 2, 7, 5]
print(list(reversed(List)))

round() Function:
Rounds a numbers

# for integers
print(round(10))

# for floating point


print(round(10.8))

# even choice
print(round(6.6))

type() Function:
Returns the type of an object

List = [4, 5]
print(type(List))

Dict = {4: 'four', 5: 'five'}


print(type(Dict))

You might also like