- 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.
- Beginning Java Data Structures and Algorithms
- Magento 2 Theme Design(Second Edition)
- 數據結構習題解析與實驗指導
- Python語言實用教程
- OpenGL Data Visualization Cookbook
- UNIX Linux程序設計教程
- Getting Started with Nano Server
- jQuery for Designers Beginner's Guide Second Edition
- 交互式程序設計(第2版)
- Photoshop CC移動UI設計案例教程(全彩慕課版·第2版)
- 從零開始學Unity游戲開發:場景+角色+腳本+交互+體驗+效果+發布
- Unity 5 Game Optimization
- 零基礎C語言學習筆記
- GO語言編程從入門到實踐
- 熱處理常見缺陷分析與解決方案