Module 3 Flashcards
an instruction that a Python interpreter can execute
Statement
Python statement ends with the token NEWLINE character. But we can extend the statement over multiple
lines using line continuation character (). This is known as an explicit continuation.
Multi-Line Statements
We can use parentheses () to write a multi-line statement. We can add a line continuation statement inside
it. Whatever we add inside a parentheses () will treat as a single statement even it is placed on multiple lines
Implicit continuation
contain (groups of) other statements; they affect or control the execution of those
other statements in some way.
Compound Statements
What are the Five compound statements?
if, while, for, try and with
It is a control flow statement that will execute statements under it if the condition is
true. Also known as a conditional statement.
if statement
repeatedly executes a code block while a particular
condition is true. Also known as a looping statement.
while statements
we can iterate any sequence or iterable variable. The
sequence can be string, list, dictionary, set, or tuple. Also known as a looping statement.
for statement
specifies exception handlers
try statements
Used to cleanup code for a group of statements, while the with statement allows
the execution of initialization and finalization code around a block of code.
with statements
Apart from the declaration and calculation statements, Python has various simple statements for a specific
purpose.
Simple Statements
is a null operation. Nothing happens when it executes. It is useful as a placeholder when a statement
is required syntactically, but no code needs to be executed.
The pass statement
are used to compute and write a value. An expression statement
evaluates the expression list and calculates the value.
Expression statements
used to delete objects/variables.
The del statement
we can return a value from a function when
called.
The return statement
contains the variable to delete separated by a comma.
target_list
used to import modules. We can also import individual classes from a module.
Python has a huge list of built-in modules which we can use in our code.
The import statement
used inside the loop to exit out of the loop
break Statement
skip the current iteration and move to the next iteration.
continue Statement
Terminate the current loop. Use the break statement to
come out of the loop instantly.
break
Skip the current iteration of a loop and move to the next
iteration
continue
Do nothing. Ignore the condition in which it occurred and
proceed to run the program as usual
pass
The comments are descriptions that help programmers to understand the functionality of the program. Thus,
comments are necessary while writing code in Python.
Python Comments
There is no separate way to write a ____________. Instead, we need to use a hash sign at the beginning
of each comment line to make it a ___________
Multi-Line Comments
are indicated by a hash sign(#)
Single-line Comment
a comment on the same line as a statement. Inline comments should be separated
by at least two spaces from the statement. They should start with a # and a single space.
Inline Comments
used to provide descriptions of files, classes, and functions
Block comments
We can use multi-line strings (triple quotes) to write multi-line comments. The quotation character can
either be ‘ or “. Python interpreter ignores the string literals that are not assigned to a variable.
Using String Literals for Multi-line Comments
describe Python classes, functions, constructors, methods. The docstring comment
should appear just after the declaration.
Docstring Comments
built-in module to get the list of keywords. Also, this module
allows a Python program to determine if a string is a keyword.
keyword module
reserved words that have a special meaning
Python keywords
Apart from a keyword module, we can use the _________ to get the list of
keywords
help() function
It return a sequence containing all the keywords defined for the interpreter.
keyword.kwlist
Return True if s is a Python soft keyword.
keyword.issoftkeyword(s)
Sequence containing all the soft keywords defined for the interpreter.
keyword.softkwlist
used to represent truth values, known as boolean values
True and False
returns True if both expressions are True. Otherwise, it will
return. False.
and keyword
returns a boolean True if one expression is true, and it returns False if
both values are false
or keyword
returns boolean True if the expression is false.
not keyword
returns return True if the memory address first value is equal to the second value.
is keyword
returns True if it finds a given object in the sequence (such as list, string).
in keyword