Built in functions in Python.

Built in functions:

sum()

sum () function is used to add the all elements of list.

marks=[70,60,55,80,75] temp=sum(marks) print(temp) avg=float(temp/len(marks)) print(avg)

output:

340 68.0

len()

This method is used to find the length of given list.

l1=[10,20,30,40,50] print(len(l1))

output:

5

max()

This method is used to find the maximum value present in list.

l1=[10,20,30,40,50] print(max(l1))

output:

50

min()

This method is used to find the minimum value presentin the list.

l1=[10,20,30,40,50] print(min(l1))

output:

10

shuffle()

This method is used to shuffle the value present in the list. To used the memthod shuffle, we have to import module.

import random l1=[10,20,30,40,50] random.shuffle(l1) print(l1)

output:

[50, 10, 30, 40, 20]

join()

To join the individual characters of the list if it is a string. We can combined the character into long string.

str=['P','Y','T','H','O','N'] str2=",".join(str) print(str2)

output:

P,Y,T,H,O,N

Comments

Popular posts from this blog

Introduction to Python.

Decision Making Statement.