DevNet Associate DEVASC 200-901 Official Certification Guide by Adrian Iliesiu (z-lib.org)

(andrew) #1
#get input from user in numeric format

The triple quote method is used to comment multiple
lines and can be helpful when you want to provide a bit
more context than what can fit on a single line of text.
Here is an example:


''' This is
line 2
and line 3'''

DATA TYPES AND VARIABLES


Data and variables are like the fuel and the fuel tank for a
program. You can insert various types of data into a
variable, and Python supports many types natively.
Python can also be expanded with modules to support
even more variables. A variable is really just a label that
maps to a Python object stored somewhere in memory.
Without variables, your programs would not be able to
easily identify these objects, and your code would be a
mess of memory locations.


Variables


Assigning a variable in Python is very straightforward.
Python auto types a variable, and you can reassign that
same variable to another value of a different type in the
future. (Try doing that in C!) You just need to remember
the rules for variable names:


A variable name must start with a letter or the underscore character.
A variable name cannot start with a number.
A variable name can only consist of alphanumeric characters and
underscores (A–Z, 0–9, and _).
A variable name is case sensitive (so Value and value are two different
variable names).

To assign a variable you just set the variable name equal
to the value you want, as shown in these examples:

Free download pdf