Python Functions

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Types of functions

Built-in functions (input, float, int) and functions that we define.

What's the function of arguments?

So we can direct the function to do different kinds of work when we call it at different times.

Function

Some stored code that we use. Takes an input and produces an output.

What happens when you put an integer and a floating point in an expression?

The integer is converted to a float.

Return values

The result of taking arguments from a function and doing computatio​n. Is meant to be used as a value in the calling expression.

Argument

The value we pass into the function as its input when we call it.

Parameters

The variable used in the function definition. It allows the code to access the arguments for a particular function invocation.Ex. def greet(lang), lang is the parameter.

Uses of functions

1. Organize the code into "paragraphs". 2. D.R.Y. 3. Simplify something. 4. Automatize something commonly used.

How do we put arguments in a parentheses?

After the name of the function. Ex. big=max('Hello world'). 'Hello world' is the argument.

How does the body of a function should be?

It should be indent

Fruitful function

Produces a result or return value. The return statement ends the function execution and "sends back"the result of the function.

True or false: A function definition does not execute the body of a function.

True

Void (non-fruitful) Functions

When a function does not return a value.

How do you convert a string to an integer or float?

int() or float()

A function__a pattern.

stores

After defining a function...

we can call it as many times as we need.


Ensembles d'études connexes

Chapter 2 Lesson 1-2 Study Guide

View Set

Fundamentals Exam 1 (chapter 26: safety, emerg prep)

View Set