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

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:

主站蜘蛛池模板: 于田县| 海林市| 绥阳县| 黑水县| 衡阳市| 沙坪坝区| 渭源县| 安义县| 松潘县| 宝兴县| 甘孜| 永寿县| 潞西市| 安吉县| 长沙县| 白水县| 株洲市| 崇州市| 中宁县| 靖边县| 塘沽区| 潮州市| 乐山市| 瑞丽市| 苗栗市| 石楼县| 汉寿县| 托克逊县| 任丘市| 安达市| 康乐县| 元阳县| 扶沟县| 河津市| 南平市| 新邵县| 虹口区| 旬邑县| 安庆市| 修文县| 龙井市|