Coding Final

¡Supera tus tareas y exámenes ahora con Quizwiz!

actual variable

A Python variable is a reserved memory location to store values. In other words, a variable in a python program gives data to the computer for processing. Every value in Python has a datatype. Different data types in Python are Numbers, List, Tuple, Strings, Dictionary, etc. Variables can be declared by any name or even alphabets like a, aa, abc, etc.

What is a decorator?

A decorator is a design pattern in Python that allows a user to add new functionality to an existing object without modifying its structure. Decorators are usually called before the definition of a function you want to decorate.

formal variable

A formal parameter is a variable that is initialized with a copy of an actual parameter at the point of call. The values of the actual parameters are copied into the corresponding formal parameters, position by position, left to right.

Global variable

A global variable can be used anywhere in the code.In the example below we define a global variable z. The global variable z can be used all throughout the program, inside functions or outside.A global variable can modified inside a function and change for the entire program:

Lambda application

A lambda operator can have any number of arguments but can have only one expression. It cannot contain any statements and returns a function object which can be assigned to any variable.

Recursion

A recursive function is a function defined in terms of itself via self-referential expressions. This means that the function will continue to call itself and repeat its behavior until some condition is met to return a result

string variable

A string is a list of characters in order. A character is anything you can type on the keyboard in one keystroke, like a letter, a number, or a backslash. Strings can have spaces: "hello world". An empty string is a string that has 0 characters.

Arbitrary, positional, keyword arguments. Know what each one of these are. Know what order these must be placed in. and know how to identify the key differences.

Arbitrary: Python allows us to have the arbitrary number of arguments. This is especially useful when we are not sure in the advance that how many arguments, the function would require. We define the arbitrary arguments while defining a function using the asterisk (*) sign. def fruits(*fnames): """This function displays the fruit names""" # fnames is a tuple with arguments for fruit in fnames: print(fruit) fruits("Orange","Banana","Apple","Grapes") positional: specifies an argument that can be passed either positionally or as a keyword argument. This is the default kind of parameter, for example foo and bar in the following: def func(foo, bar=None): ... positional-only: specifies an argument that can be supplied only by position. keyword:

what makes it a pure function-and know why we use it.

As it does not change the state of any variable, we are guaranteed to get the same output every time we run the function with the same input. The original list of numbers are unchanged, and we don't reference any other variables outside of the function, so it is pure.

default parameters

Default parameters allow us to initialize functions with default values. A default is used when an argument is either omitted or undefined — meaning null is a valid value. A default parameter can be anything from a number to another function.

what do we need to have recursion?

In the recursive program, the solution to the base case is provided and the solution of the bigger problem is expressed in terms of smaller problems

Local Variable

Local variables can only be reached in their scope.The example below has two local variables: x and y.The variables x and y can only be used inside the function sum, they don't exist outside of the function.Local variables cannot be used outside of their scope, this line will not work: print(x)

Partial Operation

Partial functions allow us to fix a certain number of arguments of a function and generate a new function. Example: filter_none edit play_arrow brightness_4 from functools import partial # A normal function def f(a, b, c, x): return 1000*a + 100*b + 10*c + x # A partial function that calls f with # a as 3, b as 1 and c as 4. g = partial(f, 3, 1, 4) # Calling g() print(g(5))

if statement

a = 33b = 33 if b > a: print("b is greater than a") elif a == b: print("a and b are equal")

Know the difference between a string and a variable.

a string is a value representing text a variable is a name that can refer to any value quotes, double or single, (they mean the same, but can't be matched with each other) are used to create string literals, the quotes are there to indicate that the text that they enclose is not code, it is a value

for loop

fruits = ["apple", "banana", "cherry"] for x in fruits: print(x) if x == "banana": break

while loop

i = 1 while i < 6: print(i) i += 1


Conjuntos de estudio relacionados

Stress Management Exam 4 (final)

View Set

CS008 Midterm 2- Chapter 4 Hardware

View Set

PEDs Chapt 17 Nursing Care of the Child with a Disorder of the Eyes or Ears

View Set

RNSG 1430 Thermoregulation, comfort, mobility

View Set

The Percent Proportion and Percent Equation

View Set