PCEP Vocab
operator
An ________ is a symbol that determines an operation to perform. The ______along with its arguments (operands) forms an expression that is subject to evaluation and provides a result.
Python an interpreted language. Explain.
An interpreted language is any programming language which is not in machine level code before runtime. Therefore, Python is an interpreted language.
list indexing
Any of the list's elements can be accessed using indexing. List elements are indexed by integer numbers starting from zero. Therefore, the first list element's index is 0 while the last element's index is equal to the list length minus 1. Using indices that are not integers raises the TypeError exception. For example, the following snippet prints 'a b c 0 1 2' to the screen: the_list = ['a', 'b', 'c'] counter = 0 for ix in range(len(the_list)): print(the_list[ix], end=' ') the_list[ix] = counter counter += 1 for ix in range(len(the_list)): print(the_list[ix], end=' ')
Tuple Indexing
Any of the tuple's elements can be accessed using indexing, which works in the same manner as in lists, including slicing. An attempt to access a non-existent tuple element raises the IndexError exception.
integer literal
1_111 and 1111 - are the same value -+-3 and - 3 are -3 +1 and 1 is 1 0o or 0O means its an octal value(contains only octal digits) 0x or 0X, is hexadecimal, 0X11 = 17 0b or 0B is a binary num- which contains 0s and 1s ony
Variable
A ____ is a named container able to store data. A variable's name can consist of: letters (including non-Latin ones)digits underscores (_)and must start with a letter (note: underscores count as letters). Upper- and lower-case letters are treated as different. Variable names which start with underscores play a specific role in Python - don't use them unless you know what you're doing. Variable names are not limited in length.
A dictionary is a data aggregate that gathers pairs of values.
A dictionary is a data aggregate that gathers pairs of values. The first element in each pair is called the key, and the second one is called the value. Both keys and values can be of any type.
list
A list is a data aggregate that contains a certain number (including zero) of elements of any type. Lists are sequences - they can be iterated, and the order of the elements is established. Lists are mutable - their contents may be changed. Lists can be initialized with list literals. For example, these two assignments instantiate two lists - the former is empty, while the latter contains three elements: empty_list = [] three_elements = [1, 'two', False] The number of elements contained in the list can be determined by the len() function. For example, the following snippet prints 3 to the screen: print(len(['a', 'b', 'c'])
Comments
A part of the code line which starts with hash (#), which is not a part of a string literal, is considered a comment (a part of the code which is ignored by the interpreter) For example, these two lines contain comments: # This is a line which is completely ignored by the Python interpreter. result = True # only part of this line is a comment
Tuple
A tuple, like a list, is a data aggregate that contains a certain number (including zero) of elements of any type. Tuples, like lists, are sequences, but they are immutable. You're not allowed to change any of the tuple elements, or add a new element, or remove an existing element. Attempting to break this rule will raise the TypeError exception.
floating point
A type that represents numbers with fractional parts. decimal points can contain a dot (.) or the letter e for scientific notation Here are some examples of correct float literals: 1.1 - one and one-tenth 1.0 (1. for short) - one point zero 0.1 (.1 for short) - one-tenth 1E1 - ten point zero 1e-1 - one-tenth -1.1E-1 - minus eleven hundredths 1e1 = 10.0 cus 1 * 10^1 = 10
A variable must be __________ before it can be used in a program.
A variable must be assigned (defined) before its first use - using a variable without prior definition (assignment) raises the NameError exception.
list comprehension
List comprehension allows the programmer to construct lists in a compact way. For example, the following snippet prints [1,2,3] to the screen: the_list = [x for x in range(1,4)] print(the_list)
Lists can be iterated through (traversed) by the _____loop
Lists can be iterated through (traversed) by the for loop, which allows the programmer to scan all their elements without the use of explicit indexing. For example, the following snippet prints 1 2 3 to the screen: the_list = [1,2,3] for element in the_list: print(element, end=' ')
Changing a value of the existing key is done by an assignment.
Changing a value of the existing key is done by an assignment. For example, the following snippet outputs False to the screen: attendance = {'Bob': True} attendance['Bob'] = False print(attendance['Bob'])
Dictionaries are ____ but are not _____
Dictionaries are mutable but are not sequences - the order of pairs is imposed by the order in which the keys are entered into the dictionary.
Dictionaries can be initialized with dictionary literals.
Dictionaries can be initialized with dictionary literals. For example, these assignments instantiate two dictionaries - one empty and one containing two key:value pairs: empty_dictionary = {} phone_directory = {'Emergency': 911, 'Speaking Clock': 767}
python keywords/reserved words
Protected, special words (in some cases, tells Python you are about to define a function) 'False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield'
PSF
Python Software foundation; Pythons created and distributed by the PSF. which is written mostly in the C programming language. This allows python to be easily ported and migrated to all platforms providing the ability to compile and run C language programs. This is also why the PSF implementation is often referred to as CPython. CPython is the most widely used implementation of Python.
Dynamically Typed Language
Python is a dynamically typed language, which means that a variable can freely change its type according to the last assignment it took part in.
Relational Operators
Relational operators compare their arguments to diagnose the relationship between them, and always return a Boolean value indicating the comparison result. == equal to 2 == 1 False !=not equal to 2 != 1True >greater than2 > 1True >=greater or equal 2 >= 1 True 1 >= 1, True < less than 2 < 1 False <= less or equal 2 <= 1 False 1 <= 1, True
Removing a pair from a dictionary
Removing a pair from a dictionary is done with the del instruction. For example, the following snippet outputs 0 to the screen: currencies = {'USD': 'United States dollar'} del currencies['USD'] print(len(currencies))
.append()
The .append(element) method can be used to append an element to the end of an existing list. For example, the following snippet outputs [1] to the screen: the_list = [] the_list.append(1) print(the_list)
.insert()
The .insert(at_index, element) method can be used to insert the element at the at_index of the existing list. For example, the following snippet outputs [2, 1] to the screen: the_list = [1] the_list.insert(0, 2) print(the_list)
.items()
The .items() method returns a list of two-element tuples, each filled with key:value pairs. For example, the following snippet outputs ('A', 'Alpha') ('B', 'Bravo') to the screen: phonetic = {'A': 'Alpha', 'B': 'Bravo'} for item in phonetic.items(): print(item, end=' ')
.keys()
The .keys() method returns a list of keys contained in the dictionary. For example, the following snippet outputs A B to the screen: phonetic = {'A': 'Alpha', 'B': 'Bravo'} for key in phonetic.keys(): print(key, end=' ')
.values()
The .values() method returns a list of values contained in the dictionary. For example, the following snippet outputs Alpha Bravo to the screen: phonetic = {'A': 'Alpha', 'B': 'Bravo'} for value in phonetic.values(): print(value, end=' ')
None
The ____ literal denotes an empty value and can be used to indicate that a certain item contains no usable value.
for loop
The ____ loop statement is a means allowing the programmer to repeat the execution of the selected part of the code when the number of repetitions can be determined in advance. The for statement uses a dedicated variable called a control variable, whose subsequent values reflect the status of the iteration for control_variable in range(from, to, step): instructions
The assignment operato
The _____ operator = is designed to assign a value to a variable: variable = expression For example: counter = 0 pi2 = 3.1415 ** 2 or - when more than one variable is assigned with the same value: variable_1 = variable_2 = ... = expression For example: counter = stages = 0
break
The break statement can be used inside the loop's body only, and causes immediate termination of the loop's code. If the loop is equipped with the else branch, it is omitted. For example, these two snippets print 0 1 to the screen: # break inside for for i in range(3): if i == 2: break print(i, end=' ') else: print('FINISHED') # break inside while i = 1 while True: print(i, end=' ') i += 1 if i == 3: break else: print('FINISHED')
negative indexing
The list elements can be indexed with negative numbers, too. In this case, -1 accesses the last element of the list, and -2 accesses the one before the last, and so on. The alternative first list element's index is -len(list)
The number of elements contained in the tuple can be determined by the_____
The number of elements contained in the tuple can be determined by the len() function. For example, the following snippet prints 4 to the screen: print(len((1, 2.2, '3', True)) Note the inner pair of parentheses - they cannot be omitted, as it will cause the tuple to be replaced with four independent values and will cause an error.
range() function
The range() function is a generator responsible for the creation of a series of values starting from keyword from and ending before reaching to, incrementing the current value by step. The invocation range(i, j) is the equivalent of range(i, j, 1) The invocation range(i) is the equivalent of range(0, i) For example, the following snippet prints 0,1,2, to the screen: for i in range(3): print(i, end=',') For example, the following snippet prints 2 1 0 to the screen: for i in range(2, -1, -1): print(i, end=' ')
while loop
The____ loop statement is a means allowing the programmer to repeat the execution of the selected part of the code as long the specified condition is true. The condition is checked before the loop's first turn, and therefore the loop's body may not even be executed once. The basic form of the while statement looks as follows:while condition: instructions
IndexError
This will happen if you try to use an index that is out of range for a list.
Tuples can be initialized with tuple literals.
Tuples can be initialized with tuple literals. For example, these assignments instantiate three tuples - one empty, one one-element, and one two-element: empty_tuple = () # tuple() has the same meaning one_element_tuple = tuple(1) # must not be replaced with (1)! one_element_tuple = 1, # the same effect as above two_element_tuple = (1, 2.5) two_element_tuple = 1, 2.5 # the same effect as above
Tuples can be iterated through (traversed) by the ____ loop, like lists.
Tuples can be iterated through (traversed) by the for loop, like lists. The + operator joins tuples together. The * operator multiplies tuples, just like lists.
iteration of dictionary using for loop
When iterated through by the for loop, the dictionary displays only its keys. For example, the following snippet outputs A B to the screen: phonetic = {'A': 'Alpha', 'B': 'Bravo'} for key in phonetic: print(key, end=' ')
binary operator
_____ is an operator that has two operands
unary operator
_____ is an operator with only one operand.
multi-line string
_____ is when the string may extend to more than one line of code: these literals are enclosed in a pair of trigraphs either """ or ''' strings enclosed inside apostrophes can contain quotes, and vice versa.
single-line string literals
_____, is when the string itself begins and ends in the same line of code: these literals are enclosed in a pair of ' (apostrophe) or " (quote) marks.
string
_____literals are sequences (including empty ones) of characters (digits, letters, punctuation marks, etc.). There are two kinds of string literal:
a program which is used to transform a source file into an executable binary filed is called:
a compiler. (also known as translator) designed to translate a program written in high-level programming language(like c++) into a binary code deployed inside an executable file.
programming language
a language developed by humans and used to communicate with computers. This language has a set of means to instruct a pc what to do and how
slice
a means by which the programmer can create a new list using a part of the already existing list. The most general slice looks as follows: the_list[from:to:step] and selects those elements whose indices start at from, don't exceed to, and change with step. The following assumptions are made regarding the slices: the_list[from:to] is equivalent to the_list[from:to:1] the_list[:to] is equivalent to the_list[0:to] the_list[from:] is equivalent to the_list[from:len(the_list)-1] the_list[:] is equivalent to the_list[0:len(the_list)-1] Slices - like indices - can take negative values. For example, the following snippet prints [1,2] to the screen: the_list = [0, 1, 2, 3] print(the_list[-3:-1])
Boolean literals
denote the only two possible values used by the Boolean algebra - their only acceptable denotations are True and False
input/output console operations
functions: print(), input(), sep = and end = keyword paramters, functions: int() and float()
Boolean Operators
not, and, or highest, middle, lowest priority Boolean operators demand Boolean arguments, and always result in a Boolean result. The rules governing the use of operators and parentheses remain the same, including left-sided binding. not - not false = true not true = false and- true and false = false true and true = true or - false or false - false false or true - true true or false - true true or true - true
Operators and data types
numeric operators: **, *, /, %, //, +, -, string operators: *, +, assignments and shortcut operators, unary and binary operators, priorities and binding, bitwise operators: ~, &, ^, |, <<, >>, Boolean operators: not, and, or, Boolean expressions, relational operators (==, !=, >, >=, <, <=), the accuracy of floating-point numbers, type casting.
pass keyword
pass keyword can be used to indicate that no action should be performed in the specific context. As the if instruction syntax insists that there should be at least one statement after it, the following snippet does not affect program execution: if condition: pass
compilation
performed by a one-time translation of the source program; an executable binary file is created in effect, the file can be run at any time without needing the source code, the program that performs the above translation is called compiler or translator -designed to translate a program written in high-level prg language into binary code deployed inside an executable file
string operators
priority - Highest, operator: *, Name: Replication, ex: 'a' * 3 = 'aaa' priority - middle, operator: +, Name: Concatenation, ex: 'a' + 'z' = 'az' 'z' + 'a' = 'za'
High level programming language
programming language which operates on high level of abstraction thereby allowing developer to ignore the physical details of the pc hardware, for ex. the cpu type, memory size and organization, etc. (python,javascript,c/c++ are ex of high-level languages)
source code
text encoded in any programming language. Source code is usually put inside a text file which resides inside the developers pc filesystem, while the file name's extension reveals the programming language used to write the code. for python we use .py
Unary Arithmetic Operators
the - operator: Change argument's sign-(-2) is equal to 2 the + operator: Preserve argument's sign +(-2) is equal to -2
right/left sided binding
when operators of the same priority (other than **) are placed side-by-side in the same expression, they are evaluated from left to right: therefore, the expression: 1 / 2 * 2 evaluates to 1.0, not to 0.25. This convention is called left-sided binding. when more than one ** operator is placed side-by-side in the same expression, they are evaluated from right to left: therefore, the expression: 2 xx 2 xx3 evaluates to 256 (2^8), not to 64 (4^3) - this is right-sided binding.
language is constituted by:
an alphabet: understood as a set of symbols used to build words of a certain language. a Lexis: also known as dictionary, set of words the language offers its users syntax: set of rules used to determineif a cetain sequence of words forms a valid sentence. semantics: defined as a set of rules which settles whether or not a certain phrase or sentence makes sense in a given language.
KeyError exception
an attempt to access an element whose key is absent in the dictionary raises the KeyError exception.
3 basic groups of operators in python
arithmetic, whose arguments are numbers; string, which operates on strings or strings and numbers; Boolean, which expects that their arguments are Boolean values.
________cannot be directly executed by a pc
Source code. To make this possible, the source code has to be translated into machine code accepted by a target pc and its cpu. This can be done using compilation or interpretation
Operator symbols
** - exponentiation result type - int if both are ints, float otherwise * - multiplication, 2 * 3, int if both are ints, float otherwise / - division, 4/2 - 2.0, always float, raises ZeroDivisionError when divider is 0 //- integer division, 5//2 - 2 int if both arguments are ints float otherwise raises ZeroDivisionError when divider is zero %- remainder(modulo) 5 % 2 - 1, int if both arguments are ints float otherwise raises ZeroDivisionError when divider is zero + - addition, 2 +1, int if both arguments are ints float otherwise -, subtraction, 2-1, 1 int if both arguments are ints float otherwise pairs of parentheses can be used to change the order of operations, for example: 2 + 3 * 4 evaluates to 14 (2 + 3) * 4 evaluates to 20
integer
(int for short) a type dedicated to storing integral numbers, that is, numbers that lack fractions. 1 is an int but 1.5 is a float
accessing dictionary values
Accessing a dictionary's value requires the use of its key. For example, the following line outputs 911 to the screen: print(phone_directory['Emergency'])
Adding a new pair to the dictionary
Adding a new pair to the dictionary resembles a regular assignment. For example, the following snippet outputs 2 to the screen: domains = {'au': 'Australia'} domains['at'] = 'Austria' print(len(domains))
instruction list
IL, a list of all elementary(atomic) operations which can be executed by a certain cpu. For EX, x86(used in personal pc) and arm(used in mobile devices) processors have different and incompatible instruction lists
Strings are immutable. This means that
Strings are immutable and their contents cannot be changed.
if statement
The conditional statement (the ___statement) is a means allowing the programmer to branch the execution path and to execute (or not) selected instructions when a certain condition is met (or not) if condition: instructions
continue
The continue statement can be used inside the loop's body only, and causes an immediate transition to the next iteration of the for loop, or to the while loop's condition check. For example, these two snippets print 0 2 FINISHED to the screen: # continue inside for for i in range(4): if i % 2 == 1: continue print(i, end=' ') else: print('FINISHED') # continue inside while i = -1 while i < 3: i += 1 if i % 2 != 0: continue print(i, end=' ') else: print('FINISHED')
del keyword
The del the_list[index] instruction can be used to remove any of the existing list elements. For example, the following snippet prints [] to the screen: the_list = [1] del the_list[0] print(the_list)
else branch
The else branch can be used to specify a part of the code that should be executed when the loop's body is not entered, which may happen when the range being iterated is empty or when all the range's values have already been consumed. For example, the following snippet prints 0 1 2 FINISHED to the screen: for i in range(3): print(i, end=' ') else: print('FINISHED')
The in and not in operators can be used to check whether a certain key exists in the dictionary.
The in and not in operators can be used to check whether a certain key exists in the dictionary. For example, the following line prints True False to the screen: print('Emergency' in phone_directory, 'White House' in phone_directory)
in and not in operators
The in and not in operators can check whether any value is contained inside the list or not. For example, the following snippet prints True False to the screen: the_list = [1, 'a'] print('a' in the_list, 1 not in the_list) The in and not in operators can be applied to strings to check if any string is a part of another string. An empty string is considered a part of any string, including an empty one. The in and not in operators can check whether or not any value is contained inside the tuple.
len() function in dictionaries
The len() function returns the number of pairs contained in the directory. For example, the following line outputs 0 to the screen: print(len(empty_directory))
escape sequence
if you need to put an apostrophe inside an apostrophe-limited string, or a quote inside a quote-limited string, you must precede them with the \ (backslash) sign, which acts as an escape character (a character which changes the meaning of the character that follows it); some of the most used escape sequences are: \\ - backslash \' - apostrophe \" - quote \n - newline character \r - carriage return character \t - horizontal tab character Here are some examples of correct string literals: "Hello world" 'Goodbye!' '' (an empty string) "Python's den" 'Python\'s den' """Two lines"""
a process in which the source code is immediately executed without translating it into a machine code is called
interpretation- a process in which the source code is exectued on the fly, and this process is not accompanied by the creation of the machine code
interpretation
involves a dedicated program designed to translate the source program on the fly each time it has to run, the program performing that task is called an interpreter, which means the interpreter is needed whenever the source code has to be executed. process where the source code is executed on-the-fly, this process is not accompanied by the creation of the machine code
literal
is data whose value is determined by the literal itself. Different data is codded in different ways, enabling python to determine each literal's type.
machine language
language placed at the lowest level of programming. sequence of bits(0s and 1s) which forces the CPU to execute the desired elementary operations