Glossary
Last updated
Was this helpful?
Last updated
Was this helpful?
For all the words that would be of benefit to know. If there is a word you believe should be on this list, please open an issue
.
Keywords
in programming languages are specific words that are reserved to communicate specific things to the computer. These words remain consistent across all uses of the programming language.
Truth values are the results of comparison operations or logical (Boolean) operations.
True
Definition: similar to "1", and considered TRUE in boolean logic
False
Definition: similar to "0", and considered FALSE in boolean logic
The other logical operators. Each operator has their own truth table:
and
Definition: will result into True
only if both the operands are True
not
Definition: used to invert the truth value
or
Definition: will result into True
if any the operands are True
for
Definition: used for looping, generally when we know the number of times we want to loop with any type of sequence like a list or string.
in
Definition: used to test if a sequence (list, tuple, string, etc.) contains a value. It returns TRUE
if the value is present. Its secondary use is to traverse through a sequence in a for
loop.
while
Definition: used for looping. The statements inside this type of loop will continue to execute until the condition for the while
loop evaluates to FALSE
or a break
statement is encountered.
if
Definition: used for conditional branching or decision making.
elif
Definition: short for "else if" used for conditional branching or decision making.
else
Definition: used for conditional branching or decision making if the condition is false; the last resort.
break
Definition: used to alter the loop's normal behavior; this will end the smallest loop it is in and control flows to the statement immediately below the loop.
continue
Definition: used to alter the loop's normal behavior; causes to end the current iteration of the loop, but not the whole loop.
class
Definition: used to define a new user-defined class - which is a collection of related attributes and methods that try to represent a real world situation.
def
Definition: used to define a new user-defined function.
async
Definition: coroutine keywords that denote the beginning of an asynchronous function (work in parallel). Usually followed by await
keyword.
await
Definition: coroutine keywords that denote the beginning of a promise within an asynchronous function.
NOTE: There can be as many
await
keywords within a function as needed.
del
Definition: used to delete the reference to an object.
as
Definition: used to create an alias while importing a module, giving a different name to a module while importing it.
is
Definition: used for testing object identity, by testing if the two variables refer to the same object. This will return TRUE
if the objects are identical and FALSE
if not.
None
Definition: special constant in python that represents the absence of a value or null value.
NOTE: It is an object with the datatype
NoneType
. There cannot be multipleNone
objects but can assign it to variables which would be equal to one another.None
does NOT implyFalse
,0
, or empty list/string/dict.
Exceptions are errors that suggest something went wrong while executing the program. Some examples of errors that one could encounter are IOError
, ValueError
, ZeroDivisionError
, ImportError
, NameError
, TypeError
. To catch exceptions, use try...except
blocks.
except
Definition: used with exceptions, where try...except
blocks are used to catch exceptions if they fail the try
set of instructions.
try
Definition: used with exceptions, where try...except
blocks are used to catch exceptions by trying out a set of instructions to see if an exception occur.
raise
Definition: to raise an exception explicitly.
finally
Definition: used with try...except
statements to close up resources or file streams. This ensures that the block of code inside it gets executed even if there is an unhandled exception.
from
Definition: to import specific attributes or functions into the current namespace, use from...import
.
import
Definition: used to import modules into the current namespace.
global
Definition: used to declare that a variable inside the function is global (outside the function).
NOTE: As a global variable, if we need to read the value of the variable we do not need to define it as global. If we need to modify the value of a global variable inside a function, then we must declare it with global, otherwise a local variable is created.
lambda
Definition: used to create an inline, anonymous function (function without a name), without a return
statement, consisting of an expression that is evaluated and returned.
nonlocal
Definition: used to declare that a variable inside a nested function (function inside a function) is not local to it, meaning it lies in the outer inclosing function. (similar to the global
keyword).
NOTE: If you need to modify a non-local variable inside a nested function, then we must declare it with
nonlocal
. Otherwise a local variable with that name is created inside the nested function.
pass
Definition: null statement where nothing happens when executed, mainly used as a placeholder.
return
Definition: used inside a function to exit and return a value.
NOTE: If we do not return a value explicitly,
NONE
is returned automatically.
with
Definition: statement used to wrap the execution of a block of code within methods defined by the context manager.
NOTE: "Context Manager" is a class that implements
__enter__
and__exit__
methods. Use ofwith
statement ensures that the__exit__
method is called at the end of the nested block. Tis concept is similar to the use oftry...finally
block.
yield
Definition: used inside a function like a return
statement, however it returns a generator.
NOTE: A Generator is an iterator that generates one item at a time. A large list of value will take up a lot of memory. Generators are useful in this situation as it generates only one value at a time instead of storing all the values in memory.
assert
Definition: used for debugging purposes by checking the internal state or if assumptions are true.
NOTE: If the assert condition is true, nothing will happen. But if the condition is false, the error -
AssertionError
is raised.