官术网_书友最值得收藏!

Variables and expressions

To translate a real-world problem into one that can be solved by an algorithm, there are two interrelated tasks. Firstly, select the variables, and secondly, find the expressions that relate to these variables. Variables are labels attached to objects; they are not the object itself. They are not containers for objects either. A variable does not contain the object, rather it acts as a pointer or reference to an object. For example, consider the following code:

Here we have created a variable, a, which points to a list object. We create another variable, b, which points to this same list object. When we append an element to this list object, this change is reflected in both a and b.

Python is a dynamically typed language. Variable names can be bound to different values and types during program execution. Each value is of a type, a string, or integer for example; however, the name that points to this value does not have a specific type. This is different from many languages such as C and Java where a name represents a fixed size, type, and location in memory. This means when we initialize variables in Python, we do not need to declare a type. Also, variables, or more specifically the objects they point to, can change type depending on the values assigned to them, for example:

主站蜘蛛池模板: 沁阳市| 乌兰浩特市| 曲沃县| 鄂尔多斯市| 遂平县| 湘阴县| 兰溪市| 邵武市| 西盟| 红桥区| 同仁县| 汉源县| 乐平市| 密云县| 华池县| 佛坪县| 大悟县| 左云县| 巴林右旗| 霞浦县| 金坛市| 大城县| 清涧县| 新干县| 关岭| 丹巴县| 黄浦区| 子洲县| 桂东县| 大丰市| 富民县| 浠水县| 清远市| 望城县| 浦北县| 民乐县| 辛集市| 保定市| 上虞市| 赣州市| 长春市|