#6 - Python Functions

#6 - Python Functions

By Ifeanyi Omeata


Topics:


1. Functions
2. Functions - Named Notation
3. Functions - Return keyword


1. Functions


>>Return to Menu
A function is a code block that only executes when it is invoked. Parameters are data that can be passed into a function. As a result, a function can return data.

def greeting(name,age=28):
    print("Hello " + name + ", you are " + str(age) + "!")
    print(f"Hello {name}, you are {age}!")

name = input("Enter your name: ")    
greeting(name,35)
greeting("Mary")

image.png image.png


2. Functions - Named Notation


>>Return to Menu

def greeting(name, age=28, color="red"):
 #Greets user withnamefrominput boxand “age”, if unavailable, default age is used   
    print(f"Hello {name.capitalize()}, you will be {age+1} next birthday!")
    print(f"We hear you like the color {color.lower()}!")

greeting(age=30, name="mike",color="Red")

image.png image.png


3. Functions - Return keyword


>>Return to Menu

#No returned value
def value_added_tax_1(amount):
    tax = amount * 0.25
    total_amount = amount * 1.25
print(value_added_tax_1(100))

#Returned value
def value_added_tax_2(amount):
    tax = amount * 0.25
    total_amount = amount * 1.25
    return tax, total_amount    
print(value_added_tax_2(100))

image.png

#End


Hope you enjoyed this! :) Follow me for more contents...


Get in Touch:
ifeanyiomeata.com

Youtube: youtube.com/c/IfeanyiOmeata
Linkedin: linkedin.com/in/omeatai
Twitter: twitter.com/iomeata
Github: github.com/omeatai
Stackoverflow: stackoverflow.com/users/2689166/omeatai
Hashnode: hashnode.com/@omeatai
Medium: medium.com/@omeatai
© 2022