<jupyter_start><jupyter_text>Function<jupyter_code>def fun():
    print("Jai")
fun()
# list = []
# for i in range(3):
#     x = input()
#     list.append(x)
# print(list)
x, y = input(), input()
print(x, "and", y)
#function overloading
def add(a,b):
    return a+b
 
def add(a,b,c):
    return a+b+c
 
print(add(4,5))
#use *args and **kwargs instead of above arguements
#args and kwargs
#args == tuple
#kwargs == dictionary

def fun(*args, **kwargs):
    for item in args:
         print(item)
    print("-"*50)
    for item, value in kwargs.items():
        print("{0} = {1}".format(item, value))
fun(1, 2, 3, 4, name = "Jai", age = 12, sex = "M")
#Important warning: The default value is evaluated only once. 
#This makes a difference when the default is a mutable object such as a list, dictionary, 
#or instances of most classes. For example, the following function accumulates the arguments 
#passed to it on subsequent calls: 
def fun(l, a = []):
    a.append(l)
    return a
#correct way is
def f(a, L=None):
    if L is None:
        L = []
    L.append(a)
    return L
#main
print(fun(1))
print(fun(2))
print(fun(3))
print(f(1))
print(f(2))
#program to find subset 
res = [None]*100
def subset(str, l, r):
    if l > r:
        return
    for i in range(l, r+1):
        res[l] = str[i]
        for j in range(0, l+1):
            if res[j] is not None:
                print(res[j], end = "")
        print("") #\n
        subset(str, i+1, r)
        res[l] = None

str = "abc"
subset(str, 0, len(str) - 1)
def subset_sum(arr, l, r, sum):
    if l > r:
         return
    print(sum)
    for i in range(l ,r):
        sum += arr[i];
        subset_sum(arr, i+1, r, sum);
        sum -= arr[i];

arr = [1,2,3,4];    
subset_sum(arr, 0, 4, 0);
#kwargs
#Functions can also be called using keyword arguments of the form kwarg=value
def fun(a, b = 5, c = "Hey", d = 4.6, e = True):
    print(a, b, c, d, e)
#fun(b = 3) #error : No Positional arguements
fun(5, c = 3)
fun(d = "string", a = 3) #order NO Matter if we provide kwargs
fun(a = "abc")
def function(a):
    pass
function(3)
def concat(sep='/', *args):
    return sep.join(args)
print(concat('.', 'Live', 'The', 'Code', 'With', '.', 'Me'))
print(concat("0", 'Live', 'The', 'Code', 'With', '.', 'Me'))
def parrot(voltage, state='a stiff', action='voom'):
    print("This parrot wouldn't", action, end=' ')
    print("if you put", voltage, "volts through it.", end=' ')
    print("E's", state, "!")

d = {"voltage": "four million", "state": "bleedin' demised", "action": "VOOM"}
parrot(**d)
#lambda functions

a = lambda x, y : x+y
print(a(2,4))
print((lambda x, y, z : x*y + z)(10055, 5535356, 655656))
#!important
tuple_list = [(3, "Three"), (5, "Five"), (1, "one"), (4, "Four"), (6, "six"), (2, "Two")]
#sort the list according to 1st key element
tuple_list.sort(key = lambda x:x[0])
print(tuple_list)
#Documented Strings
def func():
    """Hi There!!
        My name is <NAME>
        Welcome to the world of Python Programming
                                        Language
                           Django
                        Pyqty
                    selenium
                web scrapping
            Machine Learning
                
    """
    pass
print(func.__doc__)<jupyter_output>Hi There!!
        My name is <NAME>
        Welcome to the world of Python Programming
                                        Language
                           Django
                        Pyqty
                    selenium
                web scrapping
            Machine Learning
{'fraction_non_alphanumeric': 0.1591101098282174, 'fraction_numerical': 0.020275978597578147, 'mean_word_length': 2.322731524789523, 'pattern_counts': {'":': 3, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '532469', 'license': 'MIT', 'n_tokens_mistral': 1267, 'n_tokens_neox': 1210, 'n_words': 408, 'path': 'python_basics/control flow and functions.ipynb', 'repo_name': 'jai-singhal/data_science', 'size': '3561'}