<jupyter_start><jupyter_text>**Functions** are named blocks of code, designed to do one specific job. Information passed to a function is called anargument, and information received by a function is called a parameter.<jupyter_code># A simple function
def greet_user():
 """Display a simple greeting."""
 print("Hello!")

# Invoking/Calling a function
greet_user()
print('*'*40)
# Function name, documentation and .....
# Hint: dir(greet_user)
print('Function name -->',greet_user.__name__)
print('Function documentation/description -->', greet_user.__doc__)
# Passing an argument
def greet_user(username):
 """Display a personalized greeting."""
 print("Hello, " + username + "!")
greet_user('Leo')
# Default values for parameters
def make_pizza(topping='bacon'):
 """Make a single-topping pizza."""
 print("Have a " + topping + " pizza!")
make_pizza()
make_pizza('pepperoni')
# Returning a value
def add_numbers(x, y):
 """Add two numbers and return the sum."""
 return x + y

print(add_numbers(3, 5)) 
# function arguments, keywords
def cheeseshop(kind, *arguments, **keywords):
    print("-- Do you have any", kind, "?")
    print("-- I'm sorry, we're all out of", kind)
    for arg in arguments:
        print(arg)
    print("-" * 40)
    for kw in keywords:
        print(kw, ":", keywords[kw])

cheeseshop("Limburger", "It's very runny, sir.",
           "It's really very, VERY runny, sir.",
           shopkeeper="<NAME>",
           client="<NAME>",
           sketch="Cheese Shop Sketch")

# Built-in functions
# sorted(iteratable_item): returns a new list
print(sorted([2,1]))

# all(): returns True if all of the elements of the supplied iterable are true
print(all([2<3,1<3]))

# any(): returns True if any of the elements of the supplied iterable are true
print(any([2<3,1>3]))

# bool(): converts the value to a Boolean, using the standard Python truth testing procedure
print(bool()) # returns False
print(bool(2)) # returns True
print(bool(2>3)) # returns False

test = []
print(test,'is',bool(test)) # returns False

test = [0]
print(test,'is',bool(test)) # returns True

test = 0.0
print(test,'is',bool(test)) # returns False

test = None
print(test,'is',bool(test)) # returns False

test = True
print(test,'is',bool(test)) # returns True

test = 'Easy string'
print(test,'is',bool(test)) # returns True<jupyter_output>[1, 2]
True
True
False
True
False
[] is False
[0] is True
0.0 is False
None is False
True is True
Easy string is True
{'fraction_non_alphanumeric': 0.1478013029315961, 'fraction_numerical': 0.010993485342019544, 'mean_word_length': 4.54627539503386, 'pattern_counts': {'":': 1, '<': 9, '<?xml version=': 0, '>': 10, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '558573', 'license': 'MIT', 'n_tokens_mistral': 793, 'n_tokens_neox': 767, 'n_words': 268, 'path': '03 Deep Dive- Functions and OOPs/01_functions.ipynb', 'repo_name': 'aadhikar/python-3-basics-and-beyond', 'size': '2468'}