In an informal sense, in Python we do things with stuff. “Things” take the form of operations like addition and concatenation, and “stuff” refers to the objects on which we perform those operations. In this article , my focus is on - where do these sit in hierarchy and some conceptual understanding of what these are, and once we understand this, we move to focusing on that stuff, and the things our programs can do with it, but
Somewhat more formally, in Python, data takes the form of objects—either built-in objects that Python provides, or objects a user creates using Python classes or external language tools such as C extension libraries.
Objects are essentially just pieces of memory, with values and sets of associated operations. Everything is an object in a Python script. Even simple numbers qualify, with values (e.g., 99), and supported operations (addition, subtraction, and so on).
let’s first establish a clear picture of how this "stuff" is organized in python. This would help you understand and start using some python jargon.
Python programs can be decomposed into modules, statements, expressions, and objects, as follows:
Programs are composed of modules.
Modules contain statements.
Statements contain expressions.
Expressions create and process objects.
Let me quickly explain some of the jargon in plain English-
Modules are simply text files containing Python statements. You can ask the Python interpreter to execute the statements in such a file any number of times, and in a variety of ways—by system command lines, by file icon clicks, by options in IDE of your choice like "jupyter notebooks" , and more. Regardless of how it is
run, Python executes all the code in a module file from top to bottom each time you run the file.
Terminology around this can vary somewhat. For instance, module files are often referred to as programs in Python—that is, a program is considered to be a series of precoded statements stored in a file for repeated execution. Module are also sometimes called scripts. All of them mean same.
A statement is an instruction that the Python interpreter can execute. example print and assignment. When you type a statement on the command line, Python executes it and displays the result, if there is one. The result of a print statement is a value. Assignment statements don't produce a result.
A script usually contains a sequence of statements. If there is more than one statement, the results appear one at a time as the statements execute.
An expression is a combination of values, variables, and operators. If you type an expression on the command line, the interpreter evaluates it and displays the result . Ex when you type 1+1 - python interpreter compiles the expression into byte code and sends it to a python virtual machine which throws back "2" as the response. I have written in detail about how python does it in my previous article.
Operators are special symbols that represent computations like addition and multiplication. The values the operator uses are called operands.
Now that we understand basic jargon, lets understand what types of objects are available in Python and what can we do with those objects.
Python provides powerful object types as an intrinsic part of the language, there’s usually no need to code object implementations before you start solving problems. In fact, unless you have a need for special processing that built-in types don’t provide, you’re almost always better off using a built-in object instead of implementing your own. Here are some of the most commonly used ones.
Above previews Python’s built-in object types and some of the syntax used to code their literals—that is, the expressions that generate these objects. By no means this is comprehensive , because everything we process in Python programs is a kind of object. For instance, when we perform text pattern matching in Python, we create pattern objects, and when we perform network scripting, we use socket objects.
once you create an object, you bind its operation set for all time— you can perform only string operations on a string and list operations on a list. In formal terms, this means that Python is dynamically typed, a model that keeps track of types for you automatically instead of requiring declaration code, but it is also strongly typed,
a constraint that means you can perform on an object only operations that are valid for its type.
Now you should have some clarity on what python does and how it does some things. I would cover each of these built in objects in upcoming articles.