Python Final Exam

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

Return a copy of the string with the first character converted to upper case

str.capitalize()

Use ______(FloatValue, [decimals]) function to round off float values to desired decimal values.

float

it gives a unique name to an object and enables one object to interact with other objects

identity

what is the simplest conditional statement

if

what is the not equal operator

!=

________ are special symbols that represent computations like addition and multiplication. _________ are used to perform operations on variables and values. There are many types of __________(assignment, arithmetic, logical etc.)

operators

Returns True if one of the statements is true

or

______() function shows Unicode value of a character

ord

When an expression contains more than one operator, the order of evaluation depends on the _____ ________ __________

order of operations

Lists, strings and tuples are __________ sequences of objects

ordered

display data on the screen save it in a file, send it over the network ect.

output

If we think a bit more about this program, there is the "_____ ______" and the program. The input and output aspects are where the program interacts with the outside world. Within the program we have code and data to accomplish the task the program is designed to solve.

outside world

(________) __add__ and __eq__ methods

overloading

the type of object being used to invoke method determines which version of an __________ method will execute

overridden

_________ means having two methods with the same name but defined to perform different things

overriding

each method definition must include a first ________ (e.g., self)

parameter

Names that refer to arguments are also known as _________.

parameters

some of the functions we have seen require arguments inside the function, the arguments are assigned to variables called _________

parameters

occasionally it is useful to have a body with no statements (usually as a place keeper for code you haven't written yet). In that case, you can use the ______ statement which does nothing.

pass

________ a function as an argument is no different from ___________ any other datum

passing

_________ means existing in different forms. In python, operator overloading is one way of implementing ________

polymorphism

______________ is a very important concept in Object Oriented programming. It refers to the use of a single type entity (method, operator or object) to represent different types in different scenarios.

polymorphism

polymorphism allows us to access these overridden methods and attributes that have the same name as the parent class

polymorphism in class/methods

It removes the item specified by the key in the arguments

pop()

remove and return an arbitrary set element as the order of elements is irrelevant in sets

pop()

This method removes the item that was last inserted into the dictionary. In versions before 3.7, the ____________() method removes a random item.

popitem()

______ function is used to print/output of a value

print

evaluates the expressions and displays them, separated by one space, in the console window

print(value, ....,value)

You can also write a print function that includes two or more expressions separated by commas. In such a case, the print function evaluates the expressions and displays their results, separated by single spaces, on one line.

print(value,...,value)

A _______ in its most basic form takes some input, does some processing, and produces some output. _______ is like a network of interacting objects and orchestrate the movement of information between the objects to create a _______

program

A ________ is a sequence of instructions that specifies how to perform a specific task/computation. The computation might be something mathematical, such as solving a system of equations or finding the roots of a polynomial, but it can also be a symbolic computation, such as searching and replacing text in a document or something graphical, like processing an image or playing a video. The details look different in different languages, but a few basic instructions appear in just about every language

program

*args is internally a

tuple

iterating a list elements using _______ and _________

- FOR - WHILE

elements in a set can be added using

- add - update

Functions often require __________, that is, specific data values, to perform their tasks. Names that refer to arguments are also known as _____________.

- arguments - parameters

syntax of method definitions similar to functions

- can have required and/or default arguments, returns values, create/use temporary values - returns None when no return statement is used

the class that inherits from a parent class is called ______/______/______ class. Due to inheritance, child class will be able to access methods and variables of the parent class

- child - derived - sub

class ____Class(____Class)

- child - parent

List can be created using _______() constructor. It uses an object that could be a sequence (string, tuples) or collection (set, dictionary) or any iterator object. If no parameters are passed, it returns an empty list

list

functions can be assignment to a variable and put into a _________

list

__________ method is used to add an element at the end of the list

list.append(element)

Returns a shallow copy of a list. Changes in the new list will not be reflected in the original list.

list.copy()

_________ method is used to remove the given element from the list

list.remove(element)

When you create a variable inside a function, it is ______, which means that it only exists inside the function.

local

A ___________ call is like a detour in the flow of execution. Instead of going to the next statement, the flow jumps to the body of the function, runs the statements there, and then comes back to pick up where it left off.

function

__________ means hiding unnecessary details from the user. User don't need to know the complete working of function in order to use it.

abstraction implementation

like functions, objects are ________

abstractions

Using functions a complex problem can be divided into multiple smaller problems. It is easier to write & debug code for smaller problems.

divide and conquer

An ________ is a combination of values, variables, and operators. A value all by itself is considered an ___________, and so is a variable.

expression

Some of the functions we have used, such as the math functions, return results; for lack of a better name, we call them _________ ________

fruitful functions

Sometimes there are more than two possibilities, and we need more than two branches. One way to express a computation like that is a ______ _________

chained conditional

returns a copy of the set

copy()

Sets can be created by placing all the items (elements) inside _____ _____ ___, separated by comma, or by using the built-in set() function/constructor

curly braces { }

this layer is responsible for interacting with databases to save and restore application data

data access layer (or data) layer

________ class variables can be accessed in sub-class using ________ keyword or class name.

super

in multiple inheritance, _____() will refer to the first super class

super

to overload an operator, you define a new method using the appropriate _______ _______

method name

Create an iterator of the reversed list (it can be used to feed it to a for-loop, a generator, etc.)

reversed(listObject)

Use ______(value) function to find absolute values.

abs

_____() function shows a character associated with a Unicode

abs

Python allows the use of variable length arguments. These arguments are defined using the _______ syntax.

*args

____ operator can be used to combine two lists

+

what are the two mathematical exceptions for strings

+ and *

int("33") what value is returned

33

what is the less than operator

<

what is the less than or equal to operator

<=

The following examples use the operator _______ which compares two operands and produces True if they are equal and False otherwise

==

what is the equal operator

==

what is the greater than operator

>

A variable used in nested functions whose local scope is not defined. This means that the variable can be neither in the local nor the global scope.

Nonlocal Variable

An integer number to specify from which position to start. Default value is 0

Start (optional)

An integer number to specify at which position to stop.

Stop (required)

Dictionary elements can be added or updated using ____ _______:

[ ] brackets

The purpose of the _....._ method in a class definition is to set the instance variables to initial values. This special function gets automatically called whenever a new object of that class is instantiated.

__init__

returns true if both statements are true

and

Functions often require _________, that is, specific data values, to perform their tasks.

arguments

represented by methods of an object

behavior

The _______ statement terminates the loop containing it. Control of the program flows to the statement immediately after the body of the loop.

break

In Python, _______ and __________ statements can alter the flow of a normal loop.

break and continue

It removes all the elements from the dictionary

clear()

method empties the set

clear()

use _____ operator to check if specific element is present in a set

in

____________ is a file that contains a collection of related functions

module

When a class is derived from more than one base class it is called ________ _________. Python supports _______ __________.

multiple inheritance

methods that allow a user to modify an object's state are called _______

mutators

print function always ends its output with a _________

newline

The _________ type represents an immutable sequence of numbers and is commonly used for looping a specific number of times. _________() function can be used to generate a series of numbers within a given range. It takes 3 parameters: _________(start, stop, step)

range

______________ is the technique of making a function call itself Another example of _____: counter() function is calling itself

recursion

__________ or __________ quotes is used to print strings

single or double

index from which the search will start. Default value is 0

startIndex

represented by attributes/properties of an object

state

The relational operators work on strings. It uses ___________ values to compare. ___________ is an international character encoding standard that provides a unique number for every character across languages and scripts, making almost all characters accessible across various computer devices.

UNICODE

Lists, tuples, and range objects are ___________ as sequence types

refereed

The * operator also works on strings; it performs ________. If one of the values is a string the other has to be an integer

repetition

perform some action repeatedly usually with some variations

repetition

The ________ statement is used to skip the rest of the code inside a loop for the current iteration only. Loop does not terminate but continues on with the next iteration.

continue

the attributes that are present inside the class can be accessed using the ___ _______

dot operator

for sets if the item to remove does not exist, discard() will NOT raise an ________

error

This value is represented by _____ class. It is a real number with floating point representation. It is specified by a decimal point.

float

converts a string of digits to a floating-point value

float(value)

The _______ statement in Python is used to iterate over a sequence or other iterable objects. _______ continues until it reaches the last item in the sequence. For _______ can be used to iterate many different sequences (e.g., strings, lists, range) etc A _______ loop can have an optional else block as well. The else part is executed if the items in the sequence used in for loop exhausts.

for

Function definitions do not alter the flow of execution of the program but remember that statements inside the function are not executed until the __________ ___ _________.

function is called

len() function return different output in scenarios

function polymorphism

method returns the value of the item with the specified key.

get()

A variable declared inside the function's body is known as a _______ variable. A ______ variable can be accessed inside the function in which it is defined.

local variable

_________ _______ are used combine two conditions/Boolean expressions. These operators return a Boolean value.

logical operators

set elements can be accessed using a ______ through the set elements

loop

All the uppercase letters have a _______ value to all the lowercase letters

lower

A _________ is like a positionally ordered collection of items. Some of the important ________ in Python are: Strings, Lists, Tuples

sequence

One way to think about object-oriented programming is that it separates our program into multiple "_______." Each _______ contains some code and data (like a program) and has well defined interactions with the outside world and the other _______ within the program.

zones

why use a function

strictly speaking, functions are not necessary. It is possible to construct any program, the resulting code would be extremely complex, difficult to prove correct, and almost impossible to maintain.

This method search for the first occurrence of the specified value. It returns -1 if the specified value is not found.

stringObj.find(value, startIndex, endIndex)

In general, you can't perform mathematical operations on ________, even if the ________ look like numbers, so the following are illegal:

strings

check for certain conditions and run the appropriate code

conditional execution

str(99) what value is returned

'99'

float(22) what value is returned

22.0

what is the greater than or equal to operator

>=

Dictionaries are iterable objects. ____ statement can be used to read keys & values

FOR

removes the specified index, (or the last item if index is not specified)

List.pop(index)

An ________ statement creates a new variable and gives it a value

assignment

This value is represented by _____ class. It contains positive or negative whole numbers (without fraction or decimal)

int

Like a string, a _______ is a sequence of values. A ______ can be any type of data. The values in a ______ are called elements or items. _______ are defined using square brackets [ ] __________ elements are ordered and changeable/mutable __________ elements can be accessed by using Index number. Index numbering starts with 0. 1 st element has 0 index, -1 index represents the last element _________ are mutable. It means their elements can be changed without changing the original ________ object.

list

_____ method is used to add an element at the specified index

list.insert(index, element)

the values the operator is applied to are called __________

operands

+ operators behaves different in different scenarios

polymorphism is using operators

this is the user interface of the application that presents the application's features and data to the user

presentation layer

what is the meaning of this operator (-) and syntax

subtraction and a-b

methods and variables of the parent class can be accessed in the child class method using ____() keyword or using parent class name

super

finding elements other than common elements

symmetric difference

After you initialize a variable, subsequent uses of the variable name in expressions are known as _______________ __________. When the interpreter encounters a _______ __________ in any expression, it looks up the associated value. If a name is not yet bound to a value when it is referenced, Python signals an error.

variable reference

To check for ___________, corresponding elements are compared and if all elements are equal, then it returns TRUE, otherwise FALSE.

equality

For list comparison, elements are compared in order starting from the _________ element.

first

To ensure that a function is defined before its first use, you have to know the order statements run in, which is called the _____ ____ ________. Execution always begins at the first statement of the program. Statements are run one at a time, in order from top to bottom.

flow of execution

A _______ is a chunk of code that can be called by name to perform a task. When a _______ completes its task (which is usually some kind of computation), the function may send a result back to the part of the program that called that function in the first place. Round(), abs(), print(), type(), input () and Range() are some of the key built-in _________ in Python for basic tasks. Programmers can also create their own __________.

functions

Round(), abs(), print(), type(), input () and Range() are some of the key built-in _____________ in Python for basic tasks. Programmers can also create their own ________.

functions

The object however continues to exist in memory and if no other name is bound to it, it is later automatically destroyed. This automatic destruction of unreferenced objects in Python is also called ________ __________.

garbage collection

When a variable is assigned a new value, Python associates a new object (a chunk of memory) to the variable for referencing that value and the old object goes to the ______ ___________

garbage collector

The ________ keyword is used to create global variables from a non-global scope, e.g. inside a function

global

: A variable declared outside of the function is known as a ________ variable. A _____________ variable can be accessed inside or outside of the function.

global variable

- Start variable name with lower case letter. E.g. salary=4001.8$ - For constants, use all upper-case letters. E.g. TAX_RATE= 20%. - Use meaningful names for the variables.

good naming convention

You enter _______(strObj.) to receive documentation on an individual method.

help

______(ClassName) prints the documentation for the class and all of its methods

help

Python coding is based on a ______ ____ ______ that produces the various data types available to programmers

hierarchy of classes

displays the string prompt and waits for keyboard input. Returns the string of characters entered by the user

input(value)

Python has both concept of Method and Function. Functions and methods both look similar as they perform in almost similar way, but the key difference is the concept of '______ and its ______'

class and its object

________ ________ cannot be empty, but if you want a ________ ___________ with no content, put in the pass statement to avoid getting an error

class definitions

Class method that begins with ______ _______ are called special method as they have special meaning. Of one particular interest is the __init__() method

double underscore (____)

creating a new function gives you an opportunity to name a group of statements, which makes your program easier to read and debug

easy to debug

There is no limit on the number of elif statements. If there is an ____ clause, it has to be at the end, but there doesn't have to be one.

else

To begin the next output on the same line as the previous one, you can place the expression _____ = "", which says "end the line with an empty string instead of a newline," at the end of the list of expressions, as follows: print(, ______ = "")

end

A ________ ___________ is an expression that evaluates to either true or false.

Boolean expression

_________ are like notes that can be added to provide information to the user/programmer.

Docstrings

For mathematical operators, Python follows mathematical convention. The acronym __________ is a useful way to remember the rules. Parentheses, Exponential, Multiplication & Division, Addition & Subtraction.

PEMDAS

This method removes any leading (characters at the beginning) and trailing (characters at the end) characters. White space is the default character to remove.

String.strip(characters)

index where the search for value will end. Default value is the last index of the string

endIndex

advantages of inhertiance

- code reusability - readability and maintainability of the code - helps in building real world relationship in coding

when a print statement print(10) the interpreter does the following

- creates an integer object - assign the value 10 to the integer object - displays it to the value as the output

Interpreter first evaluates the expression on the right side of the assignment symbol and then binds the variable name on the left side to this value. When this happens to the variable name for the first time, it is called _________ or ___________ the variable.

- defining - initializing

What are the logical operators?

&& [and] || [or] ! [not]

___ operator can be used to repeat the elements in the list

*

what mathematical operators are illegal with strings?

- 'chinese'-'food' - subtraction - 'eggs'/'easy' - division - 'third'*'a charm' - multiplication IF the other variable is an integer and not an string

What are the OOPs concepts?

- Inheritance - Encapsulation - Polymorphism - Abstraction - Class - Object

what is the meaning of this operator (+) and syntax

- addition and a+b

A _______ contains a collection keys and a collection of values. Each key is associated with a single value. The association of a key and a value is called a key-value pair or sometimes an item. A _______ organizes data values by association (Key-Value pairs) with other data values rather than by sequential position. Defined using curly braces { } or ______() constructor( special function) A colon (:) separates a key and its value Keys are unique within a _______ while values may not be. The values of a _______ can be of any type, but the keys must be of an immutable data type such as strings, numbers, floats or tuples. ______________ don't have indexes. _______ values can be accessed using their keys, but keys can not be accessed using values. _______ are mutable.

- dictionaries - dict() constructor

For a built-in type such as int or float, each arithmetic operator corresponds to a special method name defined for that class. To see such methods, try: ____(Object), ____(Object)

- dir - help

what is the meaning of this operator (/) and syntax

- division and a/b

____ & ____ part is optional

- elif - else

what is the meaning of this operator (**) and syntax

- exponentiation and **

In Python, there are two type conversion functions for this purpose of converting strings in input

- int for integers - float for floating point numbers

You can compare __________ and _________-point numbers using the operators ==, !=, <, >, <=, and >=.

- integers - floating

class contains

- methods - attributes/variables

Docstring can appear at three levels

- module - just after class header: to describe its purpose - after each method header: serve same role as they do for function definitions

what is the meaning of this operator (*) and syntax

- multiplication and a*b

what is the meaning of this operator (-) and syntax

- negation and -a

the class which is inherited is called a ______/______/______ class

- parent - base - super

what is the meaning of this operator (//) and syntax

- quotient and a//b

what is the meaning of this operator (%) and syntax

- remainder and modulus a%b

elements in a set can be removed using

- remove - discard

"_________", which means related to meaning. If there is a _________ _________ in your program, it will run without generating error messages, but it will not do the right thing. It will do something else. It refers to an invalid program logic that produces incorrect results when the instructions are executed. Also called ______ ________.

- semantic errors - logical errors

1. The interpreter reads a Python expression or statement, also called the _______ code, and verifies that it is well formed. In this step, the interpreter behaves like a strict English teacher who rejects any sentence that does not adhere to the grammar rules, or syntax, of the language. As soon as the interpreter encounters such an error, it halts translation with an error (e.g., Syntax) message. 2. If a Python expression is well formed, the interpreter then translates it to an equivalent form in a low-level language called ______ code. When the interpreter runs a script, it completely translates it to byte code. 3. This byte code is next sent to another software component, called the _______ _______ ______ (________), where it is executed. If another error occurs during this step, execution also halts with an error message

- source code - byte code - python virtual machine (PVM)

an object consists of

- state - behavior - identity

data types of variables can be changed using ____(), _____(), and ______() functions

- str - int - float

For class objects, not all objects are comparable using < or >, but any two objects can be compared for _____ or ______

-== -!=

Fill in the class template with a constructor ( __......__ ) and an __.....__ Method, if required.

-int -str

______ _____ variable inside inner function can be used to update _____ variable inside outer function.

-non-local -local

Here's a review of the key ideas behind overloading:

1. Operator overloading lets classes define normal Python operations. 2. Classes can overload all Python expression operators. 3. Classes can also overload built-in operations such as printing, function calls, attribute access, etc. 4. Overloading makes class instances act more like built-in types.

what are the several reasons to create functions

1. divide and conquer 2. easy to debug 3. code reusability 4. abstraction implementation

Some of the commonly used data structures in Python are:

1. lists 2. dictionaries 3. tuples 4. range 5. sets

int(3.77) what value is returned

3

Methods that allow a user to access/observe but not change the state of an object are called ________

accessors

_______ operators are used with numeric values to perform common mathematical operations. An ______ expression consists of operands and operators

arithmetic

description of the data structures used to maintain the state of an object, or its attributes, from implementers point of view

attributes/variables

this layer contains the business logic that drives the application's core functionalities. Like making decisions, calculations, evaluations, and processing the data passing between the other two layers

business logic

but methods ______ be called by its name only, we need to invoke the class by a reference of that class in which it is defined i.e., method is defined within a class and hence they are dependent on that class

cannot

classes are defined using _______ keyword. Class name is a Python identifier, typically capitalized

class

________ _____ are associated with the class and not with the object of the class. They have access to the state (e.g., class variables) of the class. These methods can modify a class state that would apply across all the instances of the class. For example, it can modify a class variable that will apply to all the instances. These methods take the first parameter (e.g., cls) as a class parameter that points to the class While using ________ _____, the first parameter is automatically passed to the ________ _____. These methods can be called using className, objectName. Calling using className is more meaningful. Use the @________ decorator to define the ________ _____.

class methods

_____ ________ are declared inside the class definition (but outside any of the instance methods). These are owned by the class. All instances of the class share these variables. Modifying a _______ __________ affects all objects instance at the same time. ________ __________ are accessed by using objectName and className

class variables

________ very fundamental to python like any other object-oriented language ______ is a user defined data type. It acts like a blueprint to create the objects of that class. It provides a means of bundling data and functionality together _________ is instantiated to create objects. Objects are like a collection of data (variables) and methods (functions) that act on those data There are some built in _______ in Python such as Int, Float, List ect. Users can also create their own __________ as their requirements

classes

functions can make a program smaller by eliminating repetitive code. Later if you make a change you only have to make it in one place

code reusability

To extract a substring, the programmer places a ______ (__) in the subscript.

colon (:)

For list _________, elements are compared in order starting from the first element. If elements include characters, then their Unicode value is used for _________.

comparison

_________ operators ==,=!, <, >, <=, >= can be used with list for comparing lists.

comparison

When a function completes its task (which is usually some kind of ______________), the function may send a result back to the part of the program that called that function in the first place.

computation

Two or more strings to form a new string using the ___________ operator ____

concatenation +

The boolean expression(x>0) after if is called the ________. If it is true, the indented statement runs. If not, nothing happens.

condition

In order to write useful programs, we almost always need the ability to check conditions and change the behavior of the program accordingly. ___________ _________ give us this ability.

conditional statements

a ________ is a data item whose value cannot change during the program's execution

constant

is print (4.4) a variable or constant

constant

Each time an object is created a method is called. That methods is named the _________.

constructor

This type of method (__init__) is also called ________ in Object Oriented Programming (OOP).

constructors

In programming, ________ _________ allow the computer to select or repeat an action. They can be used to control the flow of program execution.

control statements

If the optional argument ______ is given, only the first _________ occurrences are replaced. Default is all occurrences are replaced.

count

______ ___________ in computation starts with some given information (known as input), transforms this information according to well-defined rules, and produces new information, known as output.

data processing

___________ __________ are very fundamental element to write programs in any programming language. It can store data of different types of data. Each __________ __________ provides a particular way of storing data so it can be accessed efficiently.

data structure

A ______ ______ consists of a set of values and a set of operations that can be performed on those values. Python along with its standard library has a small set of built-in types for handling various types of data. Python is not a strongly types language like Java or C++. You don't need to define the type of variables. Some of the commonly used built-in _____ ______ are: Int, Float, String, Bool, None

data types

Operator overloading can be used to write methods that can be used to compare objects. __......__ method can be redefined to compare objects. The Python interpreter picks out equality from the other comparisons by looking for an __.......__ method when it encounters the == and != operators.

eq

________- is the process of detecting and removing of existing and potential errors/bugs.

debugging

A __________ is a function that takes a function as its only parameter and returns a function. __________ is a function returning another function, usually applied as a function transformation using the @wrapper syntax. Common examples for _________ are classmethod() and staticmethod(). The _____________ syntax is merely syntactic sugar, the following two function definitions are semantically equivalent:

decorator

____ keyword is used to define functions. A function definition specifies the name of a new function and the sequence of statements that run when the function is called

def

names assigned inside a ___________ can only be seen by the code within that ___________. You cannot even refer to such names from outside the function names assigned inside a ___________ do not clash with variables outside the ___________ even if the same names are used elsewhere

def

A _______ ______ can be specified if the specified key doesn't exist.

default value

Python allows function arguments to have _______ _______. If the function is called without the argument, its ________ _______ is used.

default value

The _....._() method is a called as a destructor method. It is called when all references to the object have been deleted i.e. when an object is garbage collected. Destructors are called when an object gets destroyed. Python has a garbage collector that handles memory management automatically ______ keyword can be also used to delete objects

del

_____ keyword can be also used to delete objects

del

keyword will delete the set completely

del

object and its attribute can be deleted using ______ keyword

del

____ keyword is used to remove the element at the specified index

del list(index)

The _del_() method is a called as a __________ method. It is called when all references to the object have been deleted i.e.; when an object is garbage collected.

destructor

_________ are called when an object gets destroyed. Python has a garbage collector that handles memory management automatically. In most cases, we don't use to define destructors as Python automatically destroys objects when not in use.

destructors

element present in one set but not in other

difference

View a complete list and documentation of string methods by entering _____(strObj).

dir

A function is called _______ ______ ______ if it contains other functions as a parameter or returns a function as an output A _______ ______ ______ expects a function and a set of data values as arguments. Argument function is applied to each data value and a set of results or a single data value is returned A _______ ______ ______separates task of transforming each data value from logic of accumulating the results.

higher order functions

A python ______ is a user defined name used to identify variables, classes, functions or other objects. It helps to differentiate one entity from another _____ can start with a letter or underscore _. Keywords cannot be used as _________ _________ are case sensitive An _______ can be any length. It is recommended not to have too long __________.

identifiers

The position of each character is a string is described by an ________ number. The ________ indicates the position of the character and starts from 0. ________ = 0 means the 1st character, - 1 ________ means the last character

index

In Python, one class can inherit properties from another class. This capability to inherit is called ___________.

inheritance

If _______() method is not defined for child class, it will automatically use init() method of parent class.

init

Get data from the keyboard, file, or some other device.

input

_______ function is used to ask the user for inputs. The _______ function always builds a string from the user's keystrokes and returns it to the program. After inputting strings that represent numbers, the programmer must convert them from strings to the appropriate numeric types.

input

________ methods are used to access or modify the object state. It must have a self parameter to refer to the current object. any method we create in a class will automatically be created as an ________ method. We must explicitly tell Python that it is a class method or static method

instance

accessors and mutator method are ________ methods

instance

_______ ________ are variables whose value is assigned inside a constructor or method with self. Each instance of the class will have its own copy of these variables. The attributes of an object are represented as instance variables. Each individual object has its own set of instance variables. These variables serve as storage for its state. The scope of an _______ ________ (including self) is the entire class definition. Thus, all of the class's methods are in a position to reference the instance variables. The lifetime of an _______ ________ is the lifetime of the enclosing object. _______ ________ are those attributes that are not shared by objects. Every object has its own copy of the instance attribute. _______ ________ can be accessed using the objectName (e.g., objectName.variable)

instance variable

converts a string of digits to an integer value

int(value)

_____ literals in a Python program are written without commas, and a leading negative sign indicates a negative value. In Python 3, there is no limit on the value of an _____. It can expand to the limit of the available memory

integer

finding common elements

intersection

The ____________() function checks if the object (first argument) is an instance or subclass of classinfo class (second argument).

isinstance

Dictionaries are ______, which return successive keys.

iterable

for objects in a set the update() method does not have be a set, it can be any ________ object (tuples, lists, dictionaries, etc.)

iterable

Dictionaries don't allow duplicate ______. The value of the ____ gets updated if a new value with a duplicate name is added to the dictionary.

keys

The following identifiers are used as reserved words, or ________ of the language, and cannot be used as ordinary identifiers. These words have some specific meaning for the Python interpreter, so they are not used as an identifier

keywords

There is no limit on the number of statements that can appear in the body, but there has to be at _______ _______

least one

Operators with the same precedence are evaluated from ___ to _____ (except exponentiation). Use parentheses to avoid any confusion related to the use of operators

left to right

Python has a ______ module that provides most of the familiar mathematical functions. The ______ module includes several functions that perform basic mathematical operations. ______ module has functions like pi, pow, sqrt, cos etc. To use _______ module function, use this line of code - import ______ If can also important some specific functions of the module - from ______ import pow

math

perform basic mathematical operations like addition and multiplication

math/logic

Specifies how many splits to do. Default value is -1, which is "all occurrences".

maxSplit(optional)

Python offers ___________ __________ (in, not in) to check or validate the membership of a value. It tests for membership in a sequence, such as strings, lists, or tuples.

membership operators

definitions of all the methods that its object recognize

method

if there's no need to modify an attribute do not define a ______ to do that

method

a method is a child class can be re-defined that has the same name as in the parent class. This is called

method-overriding

_________ can be created to update or read the object attributes

methods

Functions can be called only by its _____, as it is defined independently.

name

When you use a name in a program, Python creates, changes, or looks up the name in what is known as a ___________—a place where names live.

namespace

A __________ loop is a loop inside a loop. The "inner for" will be executed one time for each iteration of the "outer for"

nested

_____ is used to define a null value. It is not the same as an empty string, False, or a zero. It is a data type of the class _____Type object

none

The __________ keyword is used to work with variables inside nested functions, where the variable should not belong to the inner function

nonlocal

Reverse the result, returns False if the result is true

not

Typically all python classes are considered subclasses of a base class called '_____' as the graph below depicts

object

When str function is called with an ______, that object's __str__ method is automatically invoked

object

Without __str__() , memory address of the _______ is printed, and not its string representation

object

python classes are organized in a tree-like class hierarchy. At the top or root of this tree is ______ class.

object

A class can be assigned to a variable. This is called ________ ________

object instantiation

python is an ______-___________ _________ languages. It means that is has a specific approach to provide solutions to the given problems

object oriented programming (OOP)

the basic idea of _________ _________ ___________ (_____) is to view a problem as a collection of objects, each of which has a certain state and can perform actions. Objects are data structures consisting of data fields, methods and interactions between them.

object-oriented program

Reverse an existing list in-place (altering the original list variable)

object.reverse()

binds the parameter self in the method MethodName to the object referenced by the variable objectName

objectName.methodName(parameter)

slicing create a copy of the list, just in the reverse order (to preserve the original list). To save the changes, store it using a new variable (list)

object[: :-1]

Each condition is checked in order. If the first is false, the next is checked, and so on. If one of them is true, the corresponding branch executes, and the statement ends. Even if more than one condition is true, ______ _____ _______ true branch executes.

only the first

_________ _________ simply means defining built-in operations in a class's methods— Python automatically invokes your methods when instances of the class appear in builtin operations, and your method's return value becomes the result of the corresponding operation.

operator overloading

____________ _________ methods are never required and generally don't have defaults (apart from a handful that some classes get from object). If you don't define or inherit one, it just means that your class does not support the corresponding operation. When used, though, these methods allow classes to emulate the interfaces of built-in objects, and so appear more consistent

operator overloading

python allows to extend the meaning of some operators beyond their pre-defined meaning based on the context. This process of redefining the operator is called ______ _________. ________ ___________ is another example of an abstraction mechanism

operator overloading

Python __________ are defined to work for built-in classes (e.g., Int, String). An _________ behaves differently with different types of classes/objects.

operators

It is legal to make more than one assignment to the same variable. A new assignment makes an existing variable refer to a new value (and stop referring to the old value). A common kind of ______________ is an update, where the new value of the variable depends on the old.

reassignment

It is valid for one function to call another; it is also valid for a function to call itself. It may not be obvious why that is a good thing, but it turns out to be one of the most magical things a program can do

recursion

the object's lifetime ends when it can no longer be ___________ anywhere in a program

referenced

The python _____ statement is used in a function to _____ something to the caller program. _____ statement are used inside a function only. In Python, every function _____ something. If there are no return statements, then it _____ None. If the _____ statement contains an expression, it's evaluated first and then the value is _____. The _____ statement terminates the function execution. A function can have multiple _____ statements. When any of them is executed, the function terminates. A function can _____ multiple types of values. A function can _____ multiple values in a single _____ statement. ________ statement can be used to ________ any data structure such as lists, tuples, dictionaries etc.

return

The process of sending a result back to another part of a program is known as _______ __ _________.

returning a value

these error do not appear until after the program has started running. These errors are also called exceptions because they usually indicate that something exceptional (and bad) has happened. E.g., a/b, enter 0 for b

runtime errors

When we talk about the search for a name's value in relation to code, the term ___________ refers to a namespace: that is, the location of a name's assignment in your source code determines the ______ of the name's visibility to your code.

scope

_________ ________ can be a tuple containing class names. If a tuple is provided, then this method checks if the given object belongs to any of the classes given in the tuple.

second argument

The first parameter of a method is usually referred as ______. This parameter is bound to the object with which the method is called, so that the code within the method can reference that particular object

self

Specifies the separator to use when splitting the string. By default any whitespace is a separator

separator(optional)

_____ elements can't be accessed using an index or a key.

set

A ______ is an unordered & unindexed collection of elements. ______ don't allow duplicate elements ______ elements should be immutable objects such as string, numbers, tuples. Lists and dictionaries can't be used as ______ elements as they are mutable objects. Elements of a ______ are not in a particular order ______ are mutable. Once a ______ is created, you cannot change its items, but you can add new items. ______ are useful where order and frequency of the elements is not important. ______ can also be used to perform mathematical set operations like union, intersection, symmetric difference, etc.

sets

To keep track of which variables can be used where, it is sometimes useful to draw a ______ diagram. Like state diagrams, ______ diagrams show the value of each variable, but they also show the function each variable belongs to. the frames are arranged in a _____ that indicates which function called which and so on

stack

A _______ is a unit of code that the Python interpreter can execute. It is a unit of code that has an effect, like creating a variable or displaying a value.

statement

________ ________ are associated with the class and not with the object of the class. They DO NOT have access to the class state (e.g., class variables) These methods can not modify a class state Mainly used to create general purpose utility methods with or without parameters. These methods don't require class parameter like class methods. These methods can be called using className, objectName. Calling using className is more meaningful. Use the @____________ decorator to define a _______ _________.

static methods

An integer number to specify the increment in range elements. Default is 1

step (optional)

Classes usually include an __.....__ method that builds and returns a string representation of an object's state.

str

The function call print(objectName) also automatically runs _____(objectName) to obtain the object's string representation for output

str

The programmer can return any information that would be relevant to the users of a class. Perhaps the most important use of __.....__ is in debugging, when you often need to observe the state of an object after running another method

str

Return a copy of the string with all the cased characters converted to lower case.

str.lower()

Return a copy of the string with all occurrences of substring old replaced by new.

str.replace(old, new, [count])

Return a copy of the string with the first character of each word in upper case & all other characters in small case.

str.title()

Return a copy of the string with all the cased characters converted to uppercase.

str.upper()

In Python, _____ are arrays of bytes representing Unicode characters. A _____ is a collection of one or more characters put in a single quote, double-quote or triple quote. It is represented by ____ class.

string

In Python, a _____________ literal is a sequence of characters enclosed in quotation marks

string

_________ are IMMUTABLE which means you can't change an existing ________ ______ values can't be changes in true sense, when you update values, a new object in created with the same name ________ object does not support item assignment

string

glues the two string together and returns the result

string 1 + string 2

The + operator performs ______ __________, which means it joins the strings by linking them end-to-end.

string concatenation

returns a list of the words contained in an input string. Separator, maxsplit are optional

string.split(separator, maxsplit)

This method returns the number of occurrence of the specified value

stringObj.count(value)

"________" refers to the structure of a program and the rules about that structure. For example, parentheses have to come in matching pairs, so (1 + 2) is legal, but 8) is a _______ ______. If there is a syntax error anywhere in your program, Python displays an error message and quits, and you will not be able to run the program.

syntax error

A _______ is a sequence of values. The values can be any type, and they are indexed by integers. _______ are defined by using circular parentheses () The difference between lists and _______ is that the _______ are immutable. _______ doesn't allow to change its content/items. _______ can be created from other objects (e.g., lists, range) using the _______ constructor _______ elements can be accessed using index numbers. For and While statements can be used to iterate _______ elements

tuple

It returns the number of times a specified value occurs in a tuple.

tuple.count(value)

it searches the tuple for a specified value and returns the first index of where it was found

tuple.index(value)

joining of sets

union

the value to be searched. This value is required for this method to execute.

value

A ___________ is more likely a container to store the values. The values to be stored depends on the programmer whether to use integer, float, string etc.

variable

is a=5 a constant or variable

variable

A _________ identifier associates a name with a value. Conceptually, _________ name refers to the memory location where data value is stored. Data value can be changed. _________ names can be as long as you like. They can contain both letters and numbers, but they must begin with either a letter or an underscore (_). __________ must be assigned a value before it use

variables

Other functions, like print, perform an action but do not return a value. They are called _____ ___________

void functions

Loops are used in programming to repeat a specific block of code. The _______ loop in Python is used to iterate over a block of code as long as the test expression (condition) is true.

while

what are some key methods used to manipulate strings

• Find() • Replace() • Split() • Upper() • Lower() • Count() • Strip()


Conjuntos de estudio relacionados

MedSurg PrepU Ch 35 Assessment of Musculoskeletal Function

View Set

GEOG 1401 - Weather & Climate SHSU - Exams 3 & 4

View Set

Chapter 24 Nation Building and Economic Transformation in the Americas, 1800-1900

View Set

A+ Core 1 Practice Exam #4 (220-1101)

View Set