Python: Functioning

 #function 

list1=[13,134,15,12,156,34,56,72,34]

len(list1)

sum(list1)

sorted(list1)

list2=[12,13,14,16,82,98,43,21]

x=list2.sort()

print(x)

#building your own function

def add(a):

    b=a+1

    return b

add(4)

def km(a):

    print(a)

km('sachin')

def sk():

    pass

print(sk())

sk()


def printlist(stuff):

    for i,s in enumerate(stuff):

        print(i, s)

list1=[20,21,21,32,21,423,34,534]

printlist(list1)

def listing(*names):

    for name in names:

        print(name,'Thank YOu')

listing('sachin','rahul','dravid','rohan')

#scope

def thriller():
    date=2019
    return date
date=2014
print(thriller())
print(date)
def abc(x):
    print(enemy)
    return(enemy + x)
enemy=9
abc(10)
def abc():
    global xyz
    xyz=325
    return xyz
abc()
print(xyz)

def freq(string):
    word=[]
    word=string.split()
    dict1={}
    for key in word:
        dict1[key] = word.count(key)
    print(dict1)
freq("Socrates was the most influnecer philospher of the Ancient Greek rule")
def isgoodrating(rating):
    if(rating<7):
        print('Bad Rating',rating)
    else:
        print('good Rating',rating)
isgoodrating(10)
    
    

Comments