Keywords/Reserved Words and Meaning
Keywords/
Meaning
Reserved Words
and all conditions in a boolean expression must be met
as if we want to give a module a different alias
assert used for debugging purposes
break interrupt the (loop) cycle, if needed
class used to create new user defined objects
used to interrupt the current cycle, without jumping out of the whole cycle. New cycle
continue
will begin
def used to create a new user defined function
del deletes objects
elif stands for else if. If the first test evaluates to False, then it continues with the next one
is optional. The statement after the else keyword is executed, unless the condition is
else
True
except catches the exception and executes codes
exec executes Python code dynamically
finally is always executed in the end. Used to clean up resources.
for iterate over items of a collection in order that they appear
from for importing a specific variable, class or a function from a module
global access variables defined outside functions
if used to determine, which statements are going to be executed.
import import other modules into a Python script
is tests for object identity
lambda creates a new anonymous function
not negates a boolean value
or at least one condition must be met.
pass does nothing
print print to console
raise create a user defined exception
return exits the function and returns a value
try specifies exception handlers
while controlling the flow of the program
yield is used with generators
Schlumberger-Private
Comparison Operators
Operator Meaning
== Equal to
!= Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
Command
Command Meaning
>>>if x<0: If certain criteria were meet, do xxx
Print(“Negative”)
>>>x=20 If certain criteria were met, do xxx
if x<2: print(“small”) Else if, certain criteria were met, do yyy
elif x<10: print(“medium”) Else, do zzz
else: print(“large”)
>>>n=2 While n is more than 0, print n where n is reducing by 1 at every
while n>0: time
print(n)
n=n-1
>>>for i in range(0, 50, 5):
print(i)
Schlumberger-Private