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

Standard data types

With our first script complete, it is time to understand the basic data types of Python. These data types are similar to those found in other programming languages, but are invoked with a simple syntax, which is described in the following table and sections. For a full list of standard data types available in Python, visit the official documentation at https://docs.python.org/3/library/stdtypes.html:

We are about to dive into the usage of data types in Python, and recommend that you repeat this section as needed to help with comprehension. While reading through how data types are handled is important, please be at a computer where you can run Python when you work through it the first few times. We invite you to explore the data type further in your interpreter and test them to see what they are capable of.

You will find that most of our scripts can be accomplished using only the standard data types Python offers. Before we take a look at one of the most common data types, strings, we will introduce comments.

Something that is always said, and can never be said enough, is to comment your code. In Python, comments are formed by any line beginning with the pound, or more recently known as the hashtag, # symbol. When Python encounters this symbol, it skips the remainder of the line and proceeds to the next line. For comments that span multiple lines, we can use three single or double quotes to mark the beginning and end of the comments rather than using a single pound symbol for every line. What follows are examples of types of comments in a file called comments.py. When running this script, we should only see 10 printed to the console as all comments are ignored:

# This is a comment
print(5 + 5) # This is an inline comment.
# Everything to the right of the # symbol
# does not get executed
"""We can use three quotes to create
multi-line comments."""

The output is as follows:

When this code is executed, we only see the preceding at the console.

主站蜘蛛池模板: 马山县| 吉林省| 孟州市| 桑日县| 阜宁县| 博白县| 宜兰市| 枣庄市| 钦州市| 车致| 营口市| 象州县| 内乡县| 东城区| 青河县| 且末县| 麟游县| 阳曲县| 淳化县| 株洲县| 喀喇| 四川省| 洪泽县| 翼城县| 黄平县| 余江县| 娄底市| 宿松县| 溧阳市| 牙克石市| 兴安县| 郎溪县| 黄冈市| 乌拉特中旗| 延长县| 湘阴县| 吉安县| 武鸣县| 治多县| 洛阳市| 嫩江县|