<jupyter_start><jupyter_text>**Created by <NAME>****Functions****16 of November, 2020**  Content- Intro to Functions- return()- Number of Arguments    - Arbitrary Arguments, *args    - Arbitrary Keyword Arguments, **kwargs- Giving output with Information- Functions that have 2 parameters- Predefined Parameters in Functions- Local and Global Variables- Changing global variables in local area- Pass Statement  Intro to FunctionsA function is a block of code which only runs when it is called.You can pass data, known as parameters, into a function.A function can return data as a result.Less code for same transactions.<jupyter_code>print("Intro to Functions") # print() is also a function
?print #We can see details of a function with ? in the beginning
print("Intro to","Functions",sep="-") # They're parameters, argumants
len("argumant")
2*3 # For multiple 2 values, we use *. We can use a function for it.
def write_name(name): # Functions can be defined with def
    print(name)
write_name("Berkay")<jupyter_output>Berkay<jupyter_text>return<jupyter_code>def write_name(name): # Functions can be defined with def
    return name
write_name("Berkay")<jupyter_output><empty_output><jupyter_text>Number of ArgumentsBy default, a function must be called with the correct number of arguments. Meaning that if your function expects 2 arguments, you have to call the function with 2 arguments, not more, and not less.<jupyter_code>def new_function(name,subject):
    print("Good Luck in your data science adventure",name,"Today's subject is ", subject)
new_function("Berkay","Functions")<jupyter_output>Good Luck in your data science adventure Berkay Today's subject is  Functions<jupyter_text>Arbitrary Arguments, *argsIf you do not know how many arguments that will be passed into your function, add a * before the parameter name in the function definition.<jupyter_code>def choose_a_kid(*kids):
    print(kids[1], "is chosen!")
choose_a_kid("Josh","Kate","Hurry")
choose_a_kid("Josh","Kate","Hurry","Amanda","Jo","Mike")<jupyter_output>Kate is chosen!<jupyter_text>Arbitrary Keyword Arguments, **kwargsIf you do not know how many keyword arguments that will be passed into your function, add two asterisk: ** before the parameter name in the function definition.<jupyter_code>def choose_a_kid(**kids):
    print(kids["name1"], "is chosen!")
choose_a_kid(name1= "Josh",name2= "Kate",name3= "Hurry")
choose_a_kid(name1= "Josh",name2= "Kate",name3= "Hurry",name4="Berkay")<jupyter_output>Josh is chosen!<jupyter_text>Giving output with Information<jupyter_code>def square(num):
    print("Square of Input: ", num**2)
square(3)
def square(num):
    print("Input: "+ str(num))
    print("Square of Input: "+ str(num**2))
square(5)<jupyter_output>Input: 5
Square of Input: 25<jupyter_text>Functions that have 2 parameters<jupyter_code>def multiply(num1,num2): # Functions can have multiple parameters
    print(num1*num2)
multiply(5,6)
def divide(num1,num2): # Functions can have multiple parameters
    return (num1/num2)
divide(9,3)<jupyter_output><empty_output><jupyter_text>Predefined Parameters in Functions<jupyter_code>def grade(student,note=50): # Predefined Parameters should be in last
    print("Grade of ",student," is", note)
grade(student="Berkay")
grade("Berkay",note=80)<jupyter_output>Grade of  Berkay  is 80<jupyter_text>Local and Global Variables<jupyter_code>global_x = 10

def f2():
    local_x = 15
    print("Local X: ", local_x)
f2()
global_x = 10

def f2():
    local_x = 15
    print("Global X: ", global_x)
f2()
print(global_x) # We can print global x but not local x
x = 5
y = 7

def multiply(x,y):
    return x*y
multiply(2,3) # It did not get 5 and 7, because they are global<jupyter_output><empty_output><jupyter_text>Changing global variables in local area<jupyter_code>list1 = []
def add_to_list(y):
    
    global list1
    
    list1.append(y)
add_to_list(4)
list1
add_to_list(2)
list1<jupyter_output><empty_output><jupyter_text>Pass Statement<jupyter_code>def function():
    pass
function()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10952146028613714, 'fraction_numerical': 0.017760236803157376, 'mean_word_length': 6.151675485008818, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 40, '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': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '172726', 'license': 'MIT', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1290, 'n_words': 413, 'path': 'Functions.ipynb', 'repo_name': 'arindam-mallik/Data-Science-Tutorials-I', 'size': '4059'}