# Chapter4Basics.py # page 105 Defining and calling a function # To be as functional as possible -> Pythonic # Define the function by using the "def" keyword # Give it value # Return it # Execute the function by "calling" the function def userInfo(): """ This function will concatinate a first_name and last_name variable and print it as a full name with the first name then the last name """ first_name = 'Bob' # varName first_name, data type string, assigned value Bob structural last_name = 'Smith'# varName last_name, data type string, assigned value Smith structural full_name = first_name + ' ' + last_name # Bob Smith print(full_name) # call the function to execute userInfo() ''' 3 types of parameterized functions def emptyFunction() -> A empty function has no params. No data is passed to the function. def parameterizedFunction(param1, param2, ...) -> A function that has parameters MUST have the same amount of args passed to it. Expected x but got y def defaultParamFunction(param1, param2="Smith") -> A function that requires 2 params, but one has a default value. If the param2 is not passed, it uses the default value, else it uses what is passed ("Bob") Bob,Smith ("Bob","Jones") Bob,Jones. ALL the defaults HAVE TO BE at the END of the tuple ''' print("##### Paramerized Function Example #####") print() # Define the function def contactInfo(fName, lName, age): """ Contact Data Function. Expected 3 args. First Name, Last Name and Age """ firstName = fName # var = param passed lastName = lName age = age # local variable age = param age contactData = firstName + ' ' + lastName + ' ' + age print(contactData) # Call the function in our program FNAME = input("Enter the contact first name: ") LNAME = input("Enter the contact last name: ") AGE = input("Enter the contact age: ") contactInfo(FNAME,LNAME,AGE) # EOF Chapter4Basics.py