Python Is Also Dynamically Typed
Python Is Also Dynamically Typed
This means that you will not get any type errors before you run your
program as you would with some programming languages. It is especially important for you to
understand the types of data you are using in your program. More on this in just a bit. Finally, your
Python programs are interpreted by the Python interpreter. The shell is another name for the Python
interpreter.
Syntax errors are found before your program runs. These are things like missing a colon or forgetting to
indent something.
Run-time errors come from things like variables with unexpected values and operations on these values.
A breakpoint causes the program to stop execution just before the breakpoint. From there it is possible
to begin stepping over your code to determine how an error occurred.
Creating Objects
Python is an object-oriented language. All data items in Python are objects. In Python, data items that
could be thought of as similar are named by a type or class. The term type and class in Python are
synonymous: they are two names for the same thing. So when you read about types in Python you can
think of classes or vice versa. There are several built-in types of data in Python including int, float, str,
list, and dict which is short for dictionary.
Literal Values
There are two ways to create objects in Python. In a few cases, you can use a literal value to create an
object. Literal values are used when we want to set some variable to a specific value within our
program. For example, the literal 6 denotes any object with the integer value of 6.
Any number written with a decimal point is a float, whether there is a 0 or some other value after the
decimal point. If you write a number using the E or exponent notation, it is a float as well. Any number
without a decimal point is an int, unless it is written in E notation. String literals are surrounded by either
single or double quotes. List literals are surrounded by [ and ]. The [] literal represents the empty list.
The {} literal is the empty dictionary.
In general, when we want to create an object based on other object values we write the following:
variable = type(other_object_values)