<jupyter_start><jupyter_text>Function: Predefined tasks or block of statements or collection of statements which used to perform some specific task.Why we use functions ?? because of reusibiltyit work discretlyfor loop work continuosly':' = indendation Defination : what do to?Calling : repeat defination whenever neededReturn: always get something whenever we call a function<jupyter_code>def funtion():
    print('hello world')
    x=90
    
    return print("Heelo boy") # print() returns nothing
    
print(funtion())
# print function return 'None'
from math import sqrt
def primeno(no):
    for i in range(2,round(sqrt(no))+1):
            if no % i == 0:#if nnumber is divided with i then that no. is not prime no 
                return False
    return True
def main():
    if primeno(int(input('Enter number '))):
        print('Prime number. ')
    else :
        print('Not a Prime number.')
main()
        
# first 'n' prime numbers
def prime_range(start,end):
    for i in range(int(start),int(end)+1):
        if primeno(i):
            print(i,end=",")
        else :
            continue
o,t = input('Enter starting and ending number : ').strip().split()
prime_range(o,t)
## defined map funtion
def mapp(funt,seq):              # 3     [3==2]
    r=[]
    for v in seq:
        k=funt(v)
        r.append(k)
    return r

x=input('enter values as , seprated').split(',')
print("before calling",x)

x=mapp(float,x)
print("after calling",x)
    
list(map(float , input('enter values as , seperate : ').strip().split(','))) # 2nd parameter's values passed in 1st parameter<jupyter_output>enter values as , seperate : 1 4 5<jupyter_text>Type of function arguments1. positioned argument2. default argument3. keyword argument4.  var length arguments5. key with argument<jupyter_code># default argument
def asd(a,b=0):
    print(a,b)

asd(10)  # default argument
asd(10,20)

# keyword argument
def asd1(a,b=12,c=90):
    print('a =',a)
    print('b =',b)
    print('c =',c)
    print()
asd1(14)
asd1(45,111,c=77) # keyword argument

# var length argument
def even(*num): # passing list or tuples  also called 'ARBITARY PARAMETER' it is tuple reference
    print(type(num))
    for i in num:
        if i%2==0:
            print(i,end=",")

even(*map(int,input('enter SPACE seperated number"s ').split()))
print()
print(*map(str,[1,2,3,4,5,6])) # map is a object  

#next((iter(map(int,input('enter SPACE seperated number"s ').split()))))<jupyter_output>enter SPACE seperated number"s 1  3 5 8 4 
<class 'tuple'>
8,4,
1 2 3 4 5 6<jupyter_text>* represent list of parameters ** represent keyword of that list parameters like if you also want to assign some key's to that list parameters<jupyter_code>def mydata(**kwargs): # passing dictionary 
    print(type(kwargs))
    for key,value in kwargs.items():
        print('{} = {}'.format(key,value))
mydata(name='python',ver=12)
d={'1':1,'2':2,'3':3,'4':4}
mydata(name='python',ver=12)
mydata(** d ) # ** indicates as kwargs passing

mydata(suraj = 'suraj' ,)

print()

mydata(kwargs = {1,2,3,4,5})  # it work as keyword argument
mydata(likethis = {1,2,3,4,5})  # it work as keyword argument

#mydata({1,2,3,4,5}) not valid
# all types of arguments
def newfunction(pos,key=10,*args,**kwargs):  # ** means key with argument (key=value)
    """it is a doc string """    # doc string    newfunction.__doc__
    print(pos)
    print(key)
    for i in args:
        print(i)
    for i,j in kwargs.items():
        print(i,"=",j)
newfunction('position argument',key = 15 , args = [2,3,4,5,2.4,'sd'] , kwargs = {1,3,4,2,3,'asdsdf','asdfasdf'})
newfunction(555,[1,2,3,4,5,6],{'a':1})
print()
newfunction(10,45,'asd','asfadffd','wrtww','sfggfgf',name=45,asdas='asdasd') #key=90
x=0   #  global scope /global variable
def asd():
    x=12 # local scope /local variable
    print(x)
asd()
print(x)
asd()
x=90
def xx():
    global x
    x=x**2
    print(x)
print(x)
xx()
print(x)
# YOU CANNOT UPDATE GLOBAL OBJECT IN FUNCTION
x=90
def xx():
    x=x**2
    print(x)
print(x)
xx()
print(x)
# YOU CAN JUST ACCESS GLOBAL OBJECTS
m='i m global'
def fun1():
    print("fun1 = ",m)
def fun2():
    global m
    print("fun2 =",m)
    m+= ' i am second function'
    print('fun2 = ',m)
fun1()
fun2()
fun1()
import sys 
print(dir(sys))
sys.getrecursionlimit()
def fact(num):
    if num==1:
        return 1
    return num*fact(num-1)
fact(8080)
from math import sqrt
#prime number by using recursion

def nprime(num,c=2):
    if num%c==0:
        return False
    if c<=round(sqrt(num)+1):
        return nprime(num,c+1)
    return True

print(nprime(20))

if nprime(int(input('enter number = '))):
    print('prime number')
else :
    print('not a prime number')
    #hackerrank.com
def staircase(n):
    for i in range(0,n,1):
        for j in range(n-i):
            print(" ",end="")
        for j in range(i+1):
            print("#",end="")
        print()
staircase(5)

for i in range(5):
    print(('#'*(i+1)).rjust(6)) # be a smart person
def sumsub(a, b, c=0, d=0):
    return a - b + c - d

print(sumsub(12,4))
print(sumsub(42,15,d=10))
print(sumsub(42,15,0,10))
def no_return(x,y):
    c = x + y

print(no_return(4,5))

def empty_return(x,y):
    c = x + y
    return

print(empty_return(4,5))
# No mandatory to have a return statement
def f(): 
    print(s)
s = "Python"
f()
def f(): 
    print(s)
    s = "Perl"
    print(s)
    
s = "Python" 
f()
print(s) # What is the problem here,
# In f() 's' is assigned as 'Perl' when we define the function. and after calling we print the function before 
# its assignment. So, f() take value of 's' as 'perl' not 'python'

#function use global variable if it is not there in their scope
def f():
    global s
    print(s)
    s = "dog"
    print(s) 
s = "cat" 
f()
print(s)<jupyter_output>cat
dog
dog
{'fraction_non_alphanumeric': 0.15497581202487906, 'fraction_numerical': 0.03144436765722184, 'mean_word_length': 3.501555209953344, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '306602', 'license': 'Apache-2.0', 'n_tokens_mistral': 2186, 'n_tokens_neox': 2108, 'n_words': 629, 'path': '05. Functions.ipynb', 'repo_name': 'Girrajjangid/Python-Beginner-to-Advance', 'size': '5788'}