0% found this document useful (0 votes)
35 views

Python Is Also Dynamically Typed

This document discusses object-oriented programming in Python. It explains that in Python, all data items are objects belonging to a type or class. There are several built-in types like integers, floats, strings, lists and dictionaries. Objects can be created from literal values like numbers and strings or by assigning an existing object to a new variable of the same type. Creating objects from other objects allows programmers to manipulate and reuse data in their programs.

Uploaded by

Semir Hamid
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Python Is Also Dynamically Typed

This document discusses object-oriented programming in Python. It explains that in Python, all data items are objects belonging to a type or class. There are several built-in types like integers, floats, strings, lists and dictionaries. Objects can be created from literal values like numbers and strings or by assigning an existing object to a new variable of the same type. Creating objects from other objects allows programmers to manipulate and reuse data in their programs.

Uploaded by

Semir Hamid
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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.

Non-literal Object Creation


Most of the time, when an object is created, it is not created from a literal value. Of course, we need
literal values in programming languages, but most of the time we have an object already and want to
create another object by using one or more existing objects.

In general, when we want to create an object based on other object values we write the following:

variable = type(other_object_values)

You might also like