Control Statements
Computer programs need the ability to decide. In the Python language, you have several
options on how to manage the arrangement of your code. For example, you may combine
the “if” and “else” statements to create powerful hacking tools.
Let’s discuss some of the most popular control statements of Python:
The “if” Statement
The syntax of this statement is
if
…
Important Note: You must indent the statement’s “control block” (the code block that
comes after the expression).
The “if …else” Statement
To use this statement, you must use the following syntax:
if
…
else
…
The script given below checks the “ID” of the current user. If the value is zero, the
terminal will display “Hey, you are the root user.” If the value is non-zero, the resulting
message will be “Hey, you are an ordinary user.”
If userid == 0:
print “Hay, you are the root user.”
else
print “Hay, you are an ordinary user.”
Computer programs need the ability to decide. In the Python language, you have several
options on how to manage the arrangement of your code. For example, you may combine
the “if” and “else” statements to create powerful hacking tools.
Let’s discuss some of the most popular control statements of Python:
The “if” Statement
The syntax of this statement is
if
…
Important Note: You must indent the statement’s “control block” (the code block that
comes after the expression).
The “if …else” Statement
To use this statement, you must use the following syntax:
if
…
else
…
The script given below checks the “ID” of the current user. If the value is zero, the
terminal will display “Hey, you are the root user.” If the value is non-zero, the resulting
message will be “Hey, you are an ordinary user.”
If userid == 0:
print “Hay, you are the root user.”
else
print “Hay, you are an ordinary user.”
