- 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.
- 大數據戰爭:人工智能時代不能不說的事
- Go Machine Learning Projects
- 工業機器人技術及應用
- 傳感器技術實驗教程
- Windows環境下32位匯編語言程序設計
- Ceph:Designing and Implementing Scalable Storage Systems
- Linux服務與安全管理
- 計算機與信息技術基礎上機指導
- Salesforce for Beginners
- 空間機械臂建模、規劃與控制
- Learning ServiceNow
- 單片機技術項目化原理與實訓
- Hands-On Business Intelligence with Qlik Sense
- 算法設計與分析
- 計算機辦公應用培訓教程