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

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:

主站蜘蛛池模板: 阿勒泰市| 怀安县| 奇台县| 锡林浩特市| 达孜县| 紫阳县| 安龙县| 南江县| 宜宾县| 平武县| 高阳县| 呼伦贝尔市| 建昌县| 巴里| 民县| 亚东县| 威信县| 盈江县| 龙里县| 新闻| 淳化县| 舒城县| 子长县| 井陉县| 双峰县| 庆安县| 宁明县| 灵石县| 嘉禾县| 屏东市| 吴川市| 满城县| 东阳市| 闽清县| 康保县| 开原市| 西峡县| 宕昌县| 奈曼旗| 仙游县| 磐安县|