PCEP

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

low-level programming

(sometimes called "close to metal" programming): if you want to implement an extremely effective driver or graphical engine, you wouldn't use Python

underscores

*Python 3.6 has introduced _______s in numeric literals, allowing for placing single underscores between digits and after base specifiers for improved readability. This feature is not available in older versions of Python.

disadvantages of interpretation

- don't expect that interpretation will ramp your code to high speed - your code will share the computer's power with the interpreter, so it can't be really fast; - both you and the end user have to have the interpreter to run your code.

disadvantages of compilation

- the compilation itself may be a very time-consuming process - you may not be able to run your code immediately after any amendment; - you have to have as many compilers as hardware platforms you want your code to be run on.

advantages of compilation

- the execution of the translated code is usually faster; - only the user has to have the compiler - the end-user may use the code without it; - the translated code is stored using machine language, as it is very hard to understand it, your own inventions and programming tricks are likely to remain your secret.

advantages of interpretation

- you can run the code as soon as you complete it - there are no additional phases of translation; - the code is stored using programming language, not the machine one - this means that it can be run on computers using different machine languages; you don't compile your code separately for each different architecture.

method

A _______ is a specific kind of function - it behaves like a function and looks like a function, but differs in the way in which it acts, and in its invocation style. In general, a typical function invocation may look like this: result = function(arg) A typical method invocation usually looks like this: result = data.method(arg)

one-element tuple

A _______-_______ _______ may be created as follows: oneElemTup1 = ("one", ) # brackets and a comma oneElemTup2 = "one", # no brackets, just a comma

recursion

A function can call other functions or even itself. When a function calls itself, this situation is known as _______, and the function which calls itself and contains a specified termination condition (i.e., the base case - a condition which doesn't tell the function to make any further calls to that function) is called a _______ function.

print() function

A function used in a program or script that causes the Python interpreter to display a value on its output device. Text must be contained within quotes.

end=' '

A keyword parameter for the print() function that causes the function to NOT add a newline at the end of the string.

Traceback

A list of code that was executed just before an exception stopped the program.

dictionary item

If you want to access a _______ _______, you can do so by making a reference to its key inside a pair of square brackets (ex. 1) or by using the get() method (ex. 2): polEngDict = { "kwiat" : "flower", "woda" : "water", "gleba" : "soil" } item1 = polEngDict["gleba"] # ex. 1 print(item1) # outputs: soil item2 = polEngDict.get("woda") print(item2) # outputs: water

value

If you want to change the _______ associated with a specific key, you can do so by referring to the item's key name in the following way: polEngDict = { "zamek" : "castle", "woda" : "water", "gleba" : "soil" } polEngDict["zamek"] = "lock" item = polEngDict["zamek"] # outputs: lock

slicing

If you want to copy a list or part of the list, you can do it by performing _______: colors = ['red', 'green', 'orange'] copyWholeColors = colors[:] # copy the whole list copyPartColors = colors[0:2] # copy part of the list

items()

If you want to loop through a dictionary's keys and values, you can use the _______ method, e.g.: polEngDict = { "zamek" : "castle", "woda" : "water", "gleba" : "soil" } for key, value in polEngDict.items(): print("Pol/Eng ->", key, ":", value)

or

if any of the operands are true, the condition is true, e.g., (True or False) is True,

and

if both operands are true, the condition is true, e.g., (True and True) is True

sep=' '

keyword parameter for the print() function that causes the function to insert the characters contained between the quotes between arguments

interpretation

you (or any user of the code) can translate the source program each time it has to be run; the program performing this kind of transformation is called an interpreter, as it interprets the code every time it is intended to be executed; it also means that you cannot just distribute the source code as-is, because the end-user also needs the interpreter to execute it.

operator

special symbols or keywords which are able to operate on the values and perform (mathematical) operations, e.g., the * operator multiplies two values: x * y

Cython

write your mathematical ideas using Python, and when you're absolutely sure that your code is correct and produces valid results, you can translate it into "C". Certainly, "C" will run much faster than pure Python.

indexed and updated

Lists can be _______ ___ _______ , e.g.: myList = [1, None, True, 'I am a string', 256, 0] print(myList[3]) # outputs: I am a string print(myList[-1]) # outputs: 0 myList[1] = '?' print(myList) # outputs: [1, '?', True, 'I am a string', 256, 0] myList.insert(0, "first") myList.append("last") print(myList) # outputs: ['first', 1, '?', True, 'I am a string',

iterated

Lists can be _______ through using the for loop, e.g.: myList = ["white", "purple", "blue", "yellow", "green"] for color in myList: print(color)

+ (addition)

adds two numbers

applications for mobile devices

although this territory is still waiting to be conquered by Python, it will most likely happen someday.

** (double asterisk)

an exponentiation (power) operator. Its left argument is the base, its right, the exponent

// (double slash)

an integer divisional operator. results are always rounded (unless the divisor or dividend is a float)

unary operator

an operator with only one operand, e.g., -1, or +3

binary operator

an operator with two operands, e.g., 4 + 5, or 12 % 5

elif

stands for else if. if the first test evaluates to False, continues with the next one

for loop

executes a set of statements many times; it's used to iterate over a sequence or other objects that are iteratable (e.g., strings). You can use the _______ _______ to iterate over a sequence of numbers using the built-in range function. Look at the examples below: Example 1: word = "Python" for letter in word: print(letter, end="*") Example 2: for i in range(1, 10): if i % 2 == 0: print(i)

while loop

executes a statement or a set of statements as long as a specified boolean condition is true, e.g.: Example 1: while True: print("Stuck in an infinite loop.") Example 2: counter = 5 while counter > 2: print(counter) counter -= 1

scientific notation in python

3E8 is equal to 3 x 10(8) 6.62607E-34 is equal to 6.62607 x 10(-34)

function

A _______ is a block of code that performs a specific task when the function is called (invoked). You can use functions to make your code reusable, better organized, and more readable. Functions can have parameters and return values.

deaf program

A program which doesn't get a user's input

source code

A program written in a high-level programming language.

string

A sequence of characters

scope

A variable that exists outside a function has a _______ inside the function body unless the function defines a variable of the same name Example: var = 2 def multByVar(x): return x * var print(multByVar(7)) # outputs: 14

three-parameter

An example of a _______-_______ function: def address(street, city, postalCode): print("Your address is:", street, "St.,", city, postalCode) s = input("Street: ") pC = input("Postal Code: ") c = input("City: ") address(s, c, pC)

natural language

Any one of the languages spoken that evolved naturally.

round() function

Changes a value by rounding it to a specific number of decimal places. Example: round(miles_to_kilometers, 2)

Guido van Rossum

Creator of Python

identifier

Each variable must have a unique name - an _______. A legal _______ name must be a non-empty sequence of characters, must begin with the underscore(_), or a letter, and it cannot be a Python keyword. The first character may be followed by underscores, letters, and digits. _______s in Python are case-sensitive.

content of the erroneous line

IDLE's editor window doesn't show line numbers, but it displays the current cursor location at the bottom-right corner; use it to locate the erroneous line in a long source code

same list

If you have a list l1, then the following assignment: l2 = l1 does not make a copy of the l1 list, but makes the variables l1 and l2 point to one and the _______ _______ in memory. For example: vehiclesOne = ['car', 'bicycle', 'motor'] print(vehiclesOne) # outputs: ['car', 'bicycle', 'motor'] vehiclesTwo = vehiclesOne del vehiclesOne[0] # deletes 'car' print(vehiclesTwo) # outputs: ['bicycle', 'motor']

machine language

a set of primitive instructions built into every computer. The instructions are in the form of binary code, so you have to enter binary codes for various instructions.

NameError

a short explanation of the error encountered

conjunction

In the language of logic, a connection of conditions is called a _______. Example: and

replication operator

It replicates the string the same number of times specified by the number. For example: "James" * 3 gives "JamesJamesJames"

deleted

List elements and lists can be _______, e.g.: myList = [1, 2, 3, 4] del myList[2] print(myList) # outputs: [1, 2, 4] del myList # deletes the whole list

shortcut operators

Operators like x++ which means x = x + 1 or x *=y which means x = x * y.

Rivals of Python

Perl - a scripting language originally authored by Larry Wall, more traditional, more conservative than Python, and resembles some of the good old languages derived from the classic C programming language. Ruby - a scripting language originally authored by Yukihiro Matsumoto. More innovative and more full of fresh ideas than Python. Python itself lies somewhere between these two creations.

dynamically-typed

Python is a _______ _______ language, which means you don't need to declare variables in it. To assign values to variables, you can use a simple assignment operator in the form of the equal (=) sign, i.e., var = 1.

interpreted

Python is a(n) ________ language.

assignment operator

The '=' character causes the compiler or interpreter to evaluate to the expression on its right and store the result in the variable(s) on its left.

concatenation operator

The + sign, used to glue two strings into one.

else

The _______ clause executes after the loop finishes its execution as long as it has not been terminated by break, e.g.: n = 0 while n != 3: print(n) n += 1 else: print(n, "else") print() for i in range(0, 3): print(i) else: print(i, "else")

range()

The _______ function generates a sequence of numbers. It accepts integers and returns range objects. The syntax of range() looks as follows: range(start, stop, step) Example code: for i in range(3): print(i, end=" ") # outputs: 0 1 2 for i in range(6, 1, -2): print(i, end=" ") # outputs: 6, 4, 2

len()

The _______ function may be used to check the list's length, e.g.: myList = ["white", "purple", "blue", "yellow", "green"] print(len(myList)) # outputs 5 del myList[2] print(len(myList)) # outputs 4

!= (not equal to)

The _______ operator compares the values of two operands, too. Here is the difference: if they are equal, the result of the comparison is False. If they are not equal, the result of the comparison is True.

== (equal to)

The _______ operator compares the values of two operands. If they are equal, the result of the comparison is True. If they are not equal, the result of the comparison is False.

Instruction List (IL)

The alphabet of a machine language. A complete set of known commands. Different types of computers may vary depending on the size of their _____s, and the instructions could be completely different in different models.

disjunction

The appearance of the word or means that the purchase depends on at least one of these conditions. In logic, such a compound is called a ______. Example: or

type

The characteristic of the numeric value which determines its kind, range, and application

String

The default result of the input() function is a _______

program

The instructions that control computer hardware and make it work.

error message

The interpreter will inform you where the error is located and what caused it. However, these messages may be misleading, as the interpreter isn't able to follow your exact intentions, and may detect errors at some distance from their real causes.

backslash

a special character which announces that the next character has a different meaning, e.g., _n (the newline character) starts a new output line.

floor division

The operation that divides two numbers and chops off the fraction part. (another name for integer division)

float

The result produced by the division operator is always a _______

optional

The start and end parameters are _______ when performing a slice: list[start:end], e.g.: myList = [1, 2, 3, 4, 5] sliceOne = myList[2: ] sliceTwo = myList[ :2] sliceThree = myList[-2: ] print(sliceOne) # outputs: [3, 4, 5] print(sliceTwo) # outputs: [1, 2] print(sliceThree) # outputs: [4, 5]

reverse()

There is also a list method called _______, which you can use to reverse the list, e.g.: lst = [5, 3, 1, 2, 4] print(lst) lst.reverse() print(lst) # outputs: [4, 2, 1, 3, 5]

add or remove

To _______ _______ _______ a key (and the associated value), use the following syntax: myPhonebook = {} # an empty dictionary myPhonebook["Adam"] = 3456783958 # create/add a key-value pair print(myPhonebook) # outputs: {'Adam': 3456783958} del myPhonebook["Adam"] print(myPhonebook) # outputs: {}

copy

To _______ a dictionary, use the copy() method: polEngDict = { "zamek" : "castle", "woda" : "water", "gleba" : "soil" } copyDict = polEngDict.copy()

in

To check if a given key exists in a dictionary, you can use the _______ keyword: polEngDict = { "zamek" : "castle", "woda" : "water", "gleba" : "soil" } if "zamek" in polEngDict: print("Yes") else: print("No")

KeyboardInterrupt

To terminate your program, just press Ctrl-C (or Ctrl-Break on some computers). This is called a _______ _______

>= (greater than or equal to)

True if the left operand's value is greater than or equal to the right operand's value, and False otherwise

> (greater than)

True if the left operand's value is greater than the right operand's value, and False otherwise

<= (lesser than or equal to)

True if the left operand's value is less than or equal to the right operand's value, and False otherwise

< (lesser than)

True if the left operand's value is less than the right operand's value, and False otherwise

immutable

Tuples are _______, which means you cannot change their elements (you cannot append tuples, or modify, or remove tuple elements). The following snippet will cause an exception:

NoneType

a special literal that is used in Python to represent the absence of a value

return

You can use the _______ keyword to tell a function to return some value. The return statement exits the function, e.g.: def multiply(a, b): return a * b print(multiply(3, 4)) # outputs: 12 def multiply(a, b): return print(multiply(3, 4)) # outputs: None

self-commenting

When the variable is name something that describes it's purpose Example: squareArea, totalApples,

for

You can use the _______ loop to loop through a dictionary, e.g.: polEngDict = { "zamek" : "castle", "woda" : "water", "gleba" : "soil" } for item in polEngDict: print(item) # outputs: zamek # woda # gleba

delete slices

You can _______ _______ using the del instruction: myList = [1, 2, 3, 4, 5] del myList[0:2] print(myList) # outputs: [3, 4, 5] del myList[:] print(myList) # deletes the list content, outputs: []

tuple elements

You can access _______ _______ by indexing them: myTuple = (1, 2.0, "string", [3, 4], (5, ), True) print(myTuple[3]) # outputs: [3, 4]

update()

You can also insert an item to a dictionary by using the _______ method, and remove the last element by using the popitem() method, e.g.: polEngDict = {"kwiat" : "flower"} polEngDict = update("gleba" : "soil") print(polEngDict) # outputs: {'kwiat' : 'flower', 'gleba' : 'soil'} polEngDict.popitem() print(polEngDict) # outputs: {'kwiat' : 'flower'}

empty tuple

You can create an _______ _______ like this: emptyTuple = () print(type(emptyTuple)) # outputs: <class 'tuple'>

exist in a list

You can test if some items _______ _______ _ _______ or not using the keywords in and not in, e.g.: myList = ["A", "B", 1, 2] print("A" in myList) # outputs: True print("C" not in myList) # outputs: True print(2 not in myList) # outputs: False

nested lists

You can use _______ _______ in Python to create matrices (i.e., two-dimensional lists).

bitwise operators

You can use _______ _______ to manipulate single bits of data. The following sample data: x = 15, which is 0000 1111 in binary, y = 16, which is 0001 0000 in binary.

negative indices

You can use _______ _______ to perform slices, too. For example: sampleList = ["A", "B", "C", "D", "E"] newList = sampleList[2:-1] print(newList) # outputs: ['C', 'D']

global

You can use the _______ keyword followed by a variable name to make the variable's scope global, e.g.: var = 2 print(var) # outputs: 2 def retVar(): global var var = 5 return var print(retVar()) # outputs: 5 print(var) # outputs: 5

del

You can use the _______ keyword to remove a specific item, or delete a dictionary. To remove all the dictionary's items, you need to use the clear() method: polEngDict = { "zamek" : "castle", "woda" : "water", "gleba" : "soil" } print(len(polEngDict)) # outputs: 3 del polEngDict["zamek"] # remove an item print(len(polEngDict)) # outputs: 2 polEngDict.clear() # removes all the items print(len(polEngDict)) # outputs: 0 del polEngDict # removes the dictionary

sort()

You can use the _______ method to sort elements of a list, e.g.: lst = [5, 3, 1, 2, 4] print(lst) lst.sort() print(lst) # outputs: [1, 2, 3, 4, 5]

break

You use _______ to exit a loop, e.g.: text = "OpenEDG Python Institute" for letter in text: if letter == "P": break print(letter, end="")

continue

You use ________ to skip the current iteration, and continue with the next iteration, e.g.: text = "pyxpyxpyx" for letter in text: if letter == "x": continue print(letter, end="")

built-in functions

_______ _______ _______ are an integral part of Python (such as the print() function). You can see a complete list of Python built-in functions at https://docs.python.org/3/library/functions.html.

user-defined functions

_______ _______ _______ are written by users for users - you can write your own functions and use them freely in your code,

List comprehension

_______ _______ allows you to create new lists from existing ones in a concise and elegant way. The syntax of a list comprehension looks as follows: [expression for element in list if conditional] which is actually an equivalent of the following code: for element in list: if conditional: expression

Tuples

_______ are ordered and unchangeable (immutable) collections of data. They can be thought of as immutable lists. They are written in round brackets: myTuple = (1, 2, True, "a string", (3, 4), [5, 6], None) print(myTuple) myList = [1, 2, True, "a string", (3, 4), [5, 6], None] print(myList)

Dictionaries

_______ are unordered*, changeable (mutable), and indexed collections of data. (*In Python 3.6x dictionaries have become ordered by default. Each dictionary is a set of key : value pairs. You can create it by using the following syntax: myDictionary = { key1 : value1, key2 : value2, key3 : value3, }

list

a _______ is a type of data in Python used to store multiple objects. It is an ordered and mutable collection of comma-separated items between square brackets, e.g.: myList = [1, None, True, "I am a string", 256, 0]

literal

a ________ is data whose values are determined by the _______ itself

expression

a combination of values (or variables, operators, calls to functions) which evaluates to a value, e.g., 1 + 2

/ (slash)

a divisional operator

* (asterisk)

a multiplication operator

variable

a named location reserved to store values in the memory. A variable is created or initialized automatically when you assign a value to it for the first time.

Jython

can communicate with existing Java infrastructure more effectively. This is why some projects find it usable and needful. Note: the current ______ implementation follows Python 2 standards. There is no _______ conforming to Python 3, so far.

function invocation

code that calls a function into action

keyword arguments

consists of three elements: a keyword identifying the argument; an equal sign (=); and a value assigned to that argument; any keyword arguments have to be put after the last positional argument (this is very important)

quotes and escapes

desired output: I like "Monty Python" print("I like \"Monty Python\"") or print('I like "Monty Python"')

&

does a bitwise and, e.g., x & y = 0, which is 0000 0000 in binary

<<

does a bitwise left shift, e.g., y << 3 = , which is 1000 0000 in binary

~

does a bitwise not, e.g., ˜ x = 240, which is 1111 0000 in binary

|

does a bitwise or, e.g., x | y = 31, which is 0001 1111 in binary

>>

does a bitwise right shift, e.g., y >> 1 = 8, which is 0000 1000 in binary

^

does a bitwise xor, e.g., x ^ y = 31, which is 0001 1111 in binary

floating point numbers

non-empty decimal fractions

function argument

passed in for function parameter function(_______)

right-to-left

print(2 ** 2 ** 3) = 256 This is because exponents are calculated with _____ _____ _____ binding.

% (modulo)

remainder left after the integer division example: print(14 % 4) is equal to 2

- (subtraction)

subtraction, and can also change the sign of a number

not

returns false if the result is true, and returns true if the result is false, e.g., not True is False.

high-level programming languages

somewhat similar to natural languages in that they use symbols, words and conventions readable to humans. These languages enable humans to express commands to computers that are much more complex than those offered by ILs.

float()

the _______ function takes one argument (e.g., a string: float(string)) and tries to convert it into a float (the rest is the same).

int()

the ________ function takes one argument (e.g., a string: int(string)) and tries to convert it into an integer. If it fails, the whole program will fail too. example: ______(input("Please input a value here: ")

source file

the file containing the source code

end a program

the input() function can be used to prompt the user to _______ _ _______. Look at the code below: name = input("Enter your name: ") print("Hello, " + name + ". Nice to meet you!") print("\nPress Enter to _______ _ _______.") input() print("THE END.")

location of the error

the name of the file containing the error, line number and module name

Positional arguments

the ones whose meaning is dictated by their position, e.g., the second argument is outputted after the first, the third is outputted after the second, etc.

CPython

the reference implementation of the Python programming language. Written in C and Python, ______ is the default and most widely used implementation of the language.

compilation

the source program is translated once (however, this act must be repeated each time you modify the source code) by getting a file (e.g., an .exe file if the code is intended to be run under MS Windows) containing the machine code; now you can distribute the file worldwide; the program that performs this translation is called a compiler or translator.

0x

treats a number as a hexadecimal number (print(__123) is equal to 291

0o

treats a number as an octal number (print(__123) is equal to 83

divisor

value behind the slash

dividend

value in front of the slash

integer

whole numbers


Ensembles d'études connexes

Minerals and their properties study guide

View Set

4 Types of Readiness to Learn (PEEK)

View Set

World AP Final Exam (Mock STAAR)

View Set

Chapter 14.3 During the Interview Aplia Assignment

View Set

financial accounting tophat chp 12b

View Set

Windows Server 2016 Identity: Active Directory Maintenance & Recovery

View Set