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

Data types, variables, and the Python shell

In the next few sections, I will use a tool called the Python shell, which will help you get more comfortable using Python. The Python shell is a tool that allows the user to enter in Python commands, which get run instantaneously. This makes the Python shell a great place to quickly and easily experiment with small bits of code or new functionality in Python.

There is no easy way of saving the code that is entered in the Python shell, so it is best to use it only for experimentation.

You can run the Python shell from a Terminal. To do this, open a Terminal and, from any directory, enter one of the following depending on your configuration:

$ Python
$ python3

You should see a new command prompt within the Terminal that looks something like this:

In Python, a single instruction is called a simple statement. For now, each individual line of code represents a simple statement. The Python shell will accept one line of code at a time. The following is an example of a simple statement that adds two numbers:

>> 1+1

Notice the >> at the beginning of our command. The >> symbol indicates that the line of code should be entered into the Python shell. The >> symbol should not be copied over with the rest of the code. You can run this statement by typing it into the shell and pressing Enter.

The Python shell will print out the result of every statement that you write. When you write the previous statement in your Python shell and press Enter, you should see the result of 2 printed just preceding it. The number 2 is an example of a value in Python. Values are like the nouns of programming languages. The + symbol is an example of an operator. Operators are like the verbs of programming languages, and they express what you would like to do with a value.

主站蜘蛛池模板: 凭祥市| 芒康县| 喜德县| 贡山| 四子王旗| 乌什县| 麟游县| 肇庆市| 汨罗市| 荥阳市| 金山区| 东辽县| 中江县| 丰县| 澎湖县| 辰溪县| 吐鲁番市| 芒康县| 巴林右旗| 得荣县| 灵丘县| 清镇市| 泰兴市| 成武县| 延吉市| 钟祥市| 正安县| 临沧市| 金堂县| 伊宁市| 公主岭市| 鄂尔多斯市| 剑河县| 泸西县| 大埔县| 宜章县| 怀远县| 密山市| 湘乡市| 潍坊市| 浮山县|