gaining deeper understanding of functions Flashcards

1
Q

Global variable

A

Defined outside the scope of a function

can be accessed from within a function

provided the function does not have a local variable with the same name

updates to global variables from within a function require the use of global keyword

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Local variable

A

variables defined inside the scope of the function, the function body

can not be referenced outside the function

hide the global variable with the same name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

passing by reference

A

Basic types can be reassigned within a function

Changes made to string variables inside a function are NOT reflected outside a function

Changes made to numeric variables inside a function are NOT reflected outside a function

does not affect the variables outside the function

Complex data types such as lists, dictionaries are passed by reference

reassigning complex types within a function does not affect the origional data outside the function

updating the contetnts of a complex type within a function will update the contents outside the function as well

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Functions are first class citizens

A

everything in python is an object including the function

functions once defined, can be assigned to variables

variables can be used to invoke the function

functions can be passed in as input arguments to another function

function can be return value from a function i.e, one function can return another

Functions can be elements in a list, or tuple or dictionary

Every function name in your program should be unique

functions cannot have any name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Lambdas

A

python functions that have no name

Defining a function on the fly

Use and throw away functions which may not be reused

lambda>input arguments>:<expression></expression>

the body of lambda can only contain expression

The result of expression is the return value of the lambda

lamdas can be assigned to variables and invoked

Lambdas can be defined and invoked in a single statement

lambdas can accept any number of arguments can have default as well as variable length arguments

Lambdas are often used with built in filter() function in python

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Part of Anaconda distribution of python

A

modules available are datetime, random, os

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

python module

A

contain code for variables, functions and objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly