- Daniel Arbuckle's Mastering Python
- Daniel Arbuckle
- 269字
- 2021-07-02 21:09:29
Python basic syntax and block structure
This section primarily provides a basic understanding of the Python language constructs. If you feel you already have a solid grasp of Python, feel free to skip ahead.
Let's get down to the nuts and bolts.
A Python program is written as source code in one or more .py files and consists of statements and expressions as shown in the following screenshot:

Both statements and expressions tell Python to do something. The difference is that expressions can be combined to form more complex expressions, while statements can be combined with expressions, but not with other statements.
For example, a statement looks like this:
if 2 > 1:
An expression looks like this:
print ("One is the loneliest number")
Python source code files are executed from top to bottom as soon as they're loaded by the Python runtime. This means that for simple programs, we could just write a series of statements in a .py file and then tell Python to run them. In the preceding example, the if and else parts are statements or a single statement with two parts, if you prefer to think of it that way. Everything else is an expression. For more complex programs, we need a more structured approach.
Like most programming languages, Python lets us create functions and classes in order to organize our code.
- C# 7 and .NET Core Cookbook
- AWS Serverless架構(gòu):使用AWS從傳統(tǒng)部署方式向Serverless架構(gòu)遷移
- Practical Data Science Cookbook(Second Edition)
- Backbone.js Blueprints
- C語(yǔ)言程序設(shè)計(jì)案例精粹
- Nexus規(guī)?;疭crum框架
- Keras深度學(xué)習(xí)實(shí)戰(zhàn)
- Microsoft Dynamics AX 2012 R3 Financial Management
- Mastering AWS Security
- 深度實(shí)踐KVM:核心技術(shù)、管理運(yùn)維、性能優(yōu)化與項(xiàng)目實(shí)施
- 深入分析GCC
- Arduino電子設(shè)計(jì)實(shí)戰(zhàn)指南:零基礎(chǔ)篇
- Learning C++ by Creating Games with UE4
- UML基礎(chǔ)與Rose建模實(shí)用教程(第三版)
- JavaScript Concurrency