- Practical Data Wrangling
- Allan Visochek
- 356字
- 2021-07-02 15:16:09
Variables
In order to make effective programs, you will need to store values that you can access and modify across multiple lines of code. In Python, you can store a value using a variable. A variable is a sequence of characters that is made to represent some value in the program. To create a variable, you can use the assignment (=) operator. The assignment operator takes the value to the right and assigns it to the variable name on the left. The following statements will create a variable called myVariable and print it out:
>> myVariable = 1
>> print(myVariable)
After a variable is created, using the name of a variable in a statement is the same as using the value that the variable contains. The following are some examples of statements that use variables:
>> myVariable = 4
>> print(myVariable+2)
>> myVariable = "abc"+"cba"
>> print(myVariable+"abc")
>> myVariable = True
>> print(myVariable and True)
You can also change a variable relative to its own value. This is sometimes called incrementing (in the case of addition) or decrementing (in the case of subtraction):
>> myVariable = 0
>> myVariable = myVariable + 5
>> print(myVariable)
There is a shorthand for changing a variable based on its own value that can be used for addition, subtraction, multiplication and division. The following examples demonstrate how changing the value of a variable can be expressed more concisely. First, the following creates a variable and sets it to 0:
>> myVariable = 0.
- Machine Learning for Cybersecurity Cookbook
- 網絡綜合布線技術
- 流處理器研究與設計
- 群體智能與數據挖掘
- Zabbix Network Monitoring(Second Edition)
- Mastering Machine Learning Algorithms
- Hybrid Cloud for Architects
- Machine Learning with Apache Spark Quick Start Guide
- 分析力!專業Excel的制作與分析實用法則
- INSTANT Heat Maps in R:How-to
- Spark大數據商業實戰三部曲:內核解密|商業案例|性能調優
- 大型機系統應用基礎
- Learning iOS 8 for Enterprise
- 數字多媒體技術與應用實例
- Microsoft Office 365:Exchange Online Implementation and Migration(Second Edition)