- Python Data Structures and Algorithms
- Benjamin Baka
- 228字
- 2021-07-09 19:44:58
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:

- Mastering Ext JS(Second Edition)
- ClickHouse性能之巔:從架構設計解讀性能之謎
- HTML5移動Web開發技術
- Visual FoxPro程序設計教程(第3版)
- Linux網絡程序設計:基于龍芯平臺
- PLC編程及應用實戰
- 大學計算機基礎(第2版)(微課版)
- Spring Boot進階:原理、實戰與面試題分析
- Getting Started with Greenplum for Big Data Analytics
- Visual Basic程序設計教程
- Android驅動開發權威指南
- Java程序員面試筆試寶典(第2版)
- Scala編程(第5版)
- Image Processing with ImageJ
- 實戰Java高并發程序設計(第2版)