4 Pages
Unlock Document

University of Toronto Scarborough
Computer Science
Kathy Fellowes

CSCA08Introduction to Functions in PythonDefining a function in PythonDefining a function in Math2fxxf3 f3f5 f5Functions is a keyword in Python and cannot be used as aornameThestatement ends the function and determines the value returned to the caller If there is nothe function terminates when it reaches the bottomNotice how theof the functions is indentedThis isin PythonWe call x theof function fx is a variable accessible only from within the functionWe could usefor the parameter andor function nameThere is an important difference between a functionand a function Function CallFunction Definitiondouble3def doublenumreturn numnumprint double3mediasetredpix 135When we define a function with def Python records it but does not When we call a function Python jumps to theexecutes the whole function in order and returns to the place The purpose of functions is toand To break up a complex calculation we can use local variables inside functionsLike parameters they exist only during function executiondef polynomiala b c xExample Function with Local Variables firstaxxfunclocalvarspysecondbxthirdcreturn firstsecondthirdCSCA08Introduction to ProgrammingWeek 2FunctionsPage 1 of4
More Less

Related notes for CSCA08H3

Log In


Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.