- 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.
- PowerShell 3.0 Advanced Administration Handbook
- Excel 2007函數(shù)與公式自學寶典
- 錯覺:AI 如何通過數(shù)據(jù)挖掘誤導我們
- Dreamweaver CS3網(wǎng)頁制作融會貫通
- 計算機應(yīng)用復習與練習
- Windows XP中文版應(yīng)用基礎(chǔ)
- 電腦上網(wǎng)直通車
- RPA:流程自動化引領(lǐng)數(shù)字勞動力革命
- C語言寶典
- 控制系統(tǒng)計算機仿真
- Implementing AWS:Design,Build,and Manage your Infrastructure
- OpenStack Cloud Computing Cookbook
- 電子設(shè)備及系統(tǒng)人機工程設(shè)計(第2版)
- INSTANT Adobe Story Starter
- 工業(yè)機器人應(yīng)用系統(tǒng)三維建模