Tìm mã nguồn Python ở đâu

Có phần nào của Python có vẻ kỳ diệu không? . Làm thế nào để một trình tạo ghi nhớ trạng thái của các biến mỗi khi nó mang lại một giá trị và tại sao bạn không bao giờ phải cấp phát bộ nhớ như các ngôn ngữ khác? . Hướng dẫn này sẽ hướng dẫn bạn qua mã nguồn CPython

Bạn sẽ bao gồm tất cả các khái niệm đằng sau phần bên trong của CPython, cách chúng hoạt động và giải thích trực quan khi bạn tiếp tục

Bạn sẽ học cách

  • Đọc và điều hướng mã nguồn
  • Biên dịch CPython từ mã nguồn
  • Điều hướng và hiểu hoạt động bên trong của các khái niệm như danh sách, từ điển và trình tạo
  • Chạy bộ thử nghiệm
  • Sửa đổi hoặc nâng cấp các thành phần của thư viện CPython để đóng góp chúng cho các phiên bản sau

Vâng, đây là một bài viết rất dài. Nếu bạn vừa pha cho mình một tách trà, cà phê hoặc đồ uống yêu thích của mình, trời sẽ lạnh vào cuối Phần 1

Hướng dẫn này được chia thành năm phần. Dành thời gian của bạn cho từng phần và đảm bảo rằng bạn đã thử các bản trình diễn và các thành phần tương tác. Bạn có thể cảm nhận được thành tích mà bạn nắm bắt được các khái niệm cốt lõi của Python có thể giúp bạn trở thành một lập trình viên Python giỏi hơn

Tải xuống miễn phí. Nhận một chương mẫu từ CPython Internals. Hướng dẫn về Trình thông dịch Python 3 chỉ cho bạn cách mở khóa hoạt động bên trong của ngôn ngữ Python, biên dịch trình thông dịch Python từ mã nguồn và tham gia phát triển CPython

Phần 1. Giới thiệu về CPython

Khi bạn gõ

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
57 tại bàn điều khiển hoặc cài đặt bản phân phối Python từ python. org, bạn đang chạy CPython. CPython là một trong nhiều thời gian chạy Python, được duy trì và viết bởi các nhóm nhà phát triển khác nhau. Một số thời gian chạy khác mà bạn có thể đã nghe là PyPy, Cython và Jython

Điều độc đáo về CPython là nó chứa cả thời gian chạy và đặc tả ngôn ngữ dùng chung mà tất cả thời gian chạy Python sử dụng. CPython là triển khai "chính thức" hoặc tham chiếu của Python

Đặc tả ngôn ngữ Python là tài liệu mô tả ngôn ngữ Python. Ví dụ: nó nói rằng

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
58 là từ khóa dành riêng và
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
59 được sử dụng để lập chỉ mục, cắt và tạo danh sách trống

Hãy suy nghĩ về những gì bạn mong đợi bên trong bản phân phối Python trên máy tính của bạn

  • Khi bạn nhập
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    57 mà không có tệp hoặc mô-đun, nó sẽ đưa ra lời nhắc tương tác
  • Bạn có thể nhập các mô-đun tích hợp từ thư viện chuẩn như
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    61
  • Bạn có thể cài đặt các gói từ internet bằng cách sử dụng
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    62
  • Bạn có thể kiểm tra các ứng dụng của mình bằng thư viện
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    63 tích hợp

Đây đều là một phần của bản phân phối CPython. Có nhiều thứ hơn là một trình biên dịch

Ghi chú. Bài viết này được viết chống lại phiên bản 3. 8. 0b4 của mã nguồn CPython

Loại bỏ các quảng cáo

Có gì trong Mã nguồn?

Bản phân phối nguồn CPython đi kèm với một loạt các công cụ, thư viện và thành phần. Chúng ta sẽ khám phá những điều đó trong bài viết này. Đầu tiên chúng ta sẽ tập trung vào trình biên dịch

Để tải xuống bản sao của mã nguồn CPython, bạn có thể sử dụng

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
64 để kéo phiên bản mới nhất về bản sao đang hoạt động cục bộ

________số 8

Ghi chú. Nếu bạn không có sẵn Git, bạn có thể tải xuống nguồn trong tệp ZIP trực tiếp từ trang web GitHub

Bên trong thư mục

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
65 mới được tải xuống, bạn sẽ tìm thấy các thư mục con sau

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python

Tiếp theo, chúng tôi sẽ biên dịch CPython từ mã nguồn. Bước này yêu cầu trình biên dịch C và một số công cụ xây dựng, phụ thuộc vào hệ điều hành bạn đang sử dụng

Biên dịch CPython [macOS]

Biên dịch CPython trên macOS rất đơn giản. Trước tiên, bạn sẽ cần bộ công cụ biên dịch C thiết yếu. Công cụ phát triển dòng lệnh là một ứng dụng mà bạn có thể cập nhật trong macOS thông qua App Store. Bạn cần thực hiện cài đặt ban đầu trên thiết bị đầu cuối

Để mở một thiết bị đầu cuối trong macOS, hãy chuyển đến Launchpad, sau đó chọn Khác rồi chọn ứng dụng Terminal. Bạn sẽ muốn lưu ứng dụng này vào Dock của mình, vì vậy hãy nhấp chuột phải vào Biểu tượng và chọn Keep in Dock

Bây giờ, trong thiết bị đầu cuối, hãy cài đặt trình biên dịch C và bộ công cụ bằng cách chạy lệnh sau

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
1

Lệnh này sẽ bật lên với lời nhắc tải xuống và cài đặt một bộ công cụ, bao gồm Git, Make và trình biên dịch GNU C

Bạn cũng sẽ cần một bản sao OpenSSL đang hoạt động để sử dụng cho việc tìm nạp các gói từ PyPi. trang web tổ chức. Nếu sau này bạn có kế hoạch sử dụng bản dựng này để cài đặt các gói bổ sung, thì cần phải xác thực SSL

Cách đơn giản nhất để cài đặt OpenSSL trên macOS là sử dụng HomeBrew. Nếu bạn đã cài đặt HomeBrew, bạn có thể cài đặt các phụ thuộc cho CPython bằng lệnh

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
66

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
3

Bây giờ bạn đã có các phần phụ thuộc, bạn có thể chạy tập lệnh

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
67, kích hoạt hỗ trợ SSL bằng cách khám phá vị trí mà HomeBrew đã cài đặt và bật móc gỡ lỗi
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
68

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
6

Điều này sẽ tạo ra một

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
69 trong thư mục gốc của kho lưu trữ mà bạn có thể sử dụng để tự động hóa quá trình xây dựng. Bước
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
70 chỉ cần chạy một lần. Bạn có thể xây dựng nhị phân CPython bằng cách chạy

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
9

Cờ

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
71 cho phép
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
72 chạy đồng thời 2 công việc. Nếu bạn có 4 lõi, bạn có thể thay đổi thành 4. Cờ
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
73 ngăn
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
69 in mọi lệnh mà nó chạy ra bàn điều khiển. Bạn có thể loại bỏ cái này, nhưng đầu ra rất dài dòng

Trong quá trình xây dựng, bạn có thể gặp một số lỗi và trong bản tóm tắt, nó sẽ thông báo cho bạn rằng không phải tất cả các gói đều có thể được xây dựng. Ví dụ:

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
75,
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
76,
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
77,
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
78,
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
79,
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
80 và
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
81 sẽ không thể xây dựng với bộ hướng dẫn này. Không sao nếu bạn không có kế hoạch phát triển dựa trên các gói đó. Nếu đúng như vậy, hãy xem trang web hướng dẫn dành cho nhà phát triển để biết thêm thông tin

Quá trình xây dựng sẽ mất vài phút và tạo một tệp nhị phân có tên là

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
82. Mỗi khi bạn thay đổi mã nguồn, bạn sẽ cần chạy lại
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
72 với cùng các cờ. Tệp nhị phân
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
82 là tệp nhị phân gỡ lỗi của CPython. Thực thi
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
82 để xem REPL đang hoạt động

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
5

Ghi chú. Vâng, đúng vậy, bản dựng macOS có phần mở rộng tệp cho

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
86. Điều này không phải vì nó là tệp nhị phân của Windows. Vì macOS có hệ thống tệp không phân biệt chữ hoa chữ thường và khi làm việc với tệp nhị phân, các nhà phát triển không muốn mọi người vô tình tham chiếu đến thư mục
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
87 nên
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
86 đã được thêm vào để tránh sự mơ hồ. Nếu sau này bạn chạy
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
89 hoặc
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
90, nó sẽ đổi tên tệp trở lại
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
57

Loại bỏ các quảng cáo

Biên dịch CPython [Linux]

Đối với Linux, bước đầu tiên là tải xuống và cài đặt

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
72,
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
93,
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
67 và
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
95

Đối với Fedora Core, RHEL, CentOS hoặc các hệ thống dựa trên yum khác

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
6

Đối với Debian, Ubuntu hoặc các hệ thống dựa trên

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
96 khác

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
8

Sau đó cài đặt các gói cần thiết, cho Fedora Core, RHEL, CentOS hoặc các hệ thống dựa trên yum khác

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
9

Đối với Debian, Ubuntu hoặc các hệ thống dựa trên

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
96 khác

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
0

Bây giờ bạn đã có các phần phụ thuộc, bạn có thể chạy tập lệnh

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
67, kích hoạt móc gỡ lỗi
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
68

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
1

Xem lại đầu ra để đảm bảo rằng hỗ trợ OpenSSL được đánh dấu là

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
100. Nếu không, hãy kiểm tra bản phân phối của bạn để biết hướng dẫn cài đặt tiêu đề cho OpenSSL

Tiếp theo, bạn có thể xây dựng tệp nhị phân CPython bằng cách chạy tệp

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
69 đã tạo

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
9

Trong quá trình xây dựng, bạn có thể gặp một số lỗi và trong bản tóm tắt, nó sẽ thông báo cho bạn rằng không phải tất cả các gói đều có thể được xây dựng. Không sao nếu bạn không có kế hoạch phát triển dựa trên các gói đó. Nếu đúng như vậy, hãy xem trang web hướng dẫn dành cho nhà phát triển để biết thêm thông tin

Quá trình xây dựng sẽ mất vài phút và tạo một tệp nhị phân có tên là

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
57. Đây là nhị phân gỡ lỗi của CPython. Thực thi
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
103 để xem REPL đang hoạt động

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
3

Biên dịch CPython [Windows]

Bên trong thư mục PC là tệp dự án Visual Studio để xây dựng và khám phá CPython. Để sử dụng tính năng này, bạn cần cài đặt Visual Studio trên PC của mình

Phiên bản mới nhất của Visual Studio, Visual Studio 2019, giúp làm việc với Python và mã nguồn CPython dễ dàng hơn, vì vậy nó được khuyến nghị sử dụng trong hướng dẫn này. Nếu bạn đã cài đặt Visual Studio 2017, nó cũng sẽ hoạt động tốt

Không có tính năng trả phí nào được yêu cầu để biên dịch CPython hoặc hướng dẫn này. Bạn có thể sử dụng phiên bản Cộng đồng của Visual Studio, được cung cấp miễn phí trên trang web Visual Studio của Microsoft

Khi bạn đã tải xuống trình cài đặt, bạn sẽ được yêu cầu chọn thành phần nào bạn muốn cài đặt. Mức tối thiểu cho hướng dẫn này là

  • Khối lượng công việc Phát triển Python
  • Các công cụ phát triển gốc Python tùy chọn
  • Python 3 64-bit [3. 7. 2] [có thể bỏ chọn nếu bạn đã có Python 3. 7 đã cài đặt]

Bất kỳ tính năng tùy chọn nào khác có thể được bỏ chọn nếu bạn muốn tận tâm hơn với dung lượng ổ đĩa

Trình cài đặt sau đó sẽ tải xuống và cài đặt tất cả các thành phần cần thiết. Quá trình cài đặt có thể mất một giờ, vì vậy bạn có thể muốn đọc tiếp và quay lại phần này

Khi quá trình cài đặt hoàn tất, hãy nhấp vào nút Khởi chạy để khởi động Visual Studio. Bạn sẽ được nhắc đăng nhập. Nếu bạn có tài khoản Microsoft, bạn có thể đăng nhập hoặc bỏ qua bước đó

Khi Visual Studio khởi động, bạn sẽ được nhắc Mở Dự án. Một lối tắt để bắt đầu với cấu hình Git và nhân bản CPython là chọn tùy chọn Clone or check out code

Đối với URL của dự án, hãy nhập

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
104 để sao chép

Sau đó, Visual Studio sẽ tải xuống một bản sao CPython từ GitHub bằng phiên bản Git đi kèm với Visual Studio. Bước này cũng giúp bạn tránh được rắc rối khi phải cài đặt Git trên Windows. Quá trình tải xuống có thể mất 10 phút

Khi dự án đã được tải xuống, bạn cần trỏ nó đến tệp Giải pháp

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
105, bằng cách nhấp vào Giải pháp và Dự án và chọn
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
106

Khi giải pháp được tải, nó sẽ nhắc bạn nhắm mục tiêu lại dự án bên trong giải pháp cho phiên bản trình biên dịch C/C++ mà bạn đã cài đặt. Visual Studio cũng sẽ nhắm mục tiêu phiên bản Windows SDK mà bạn đã cài đặt

Đảm bảo rằng bạn thay đổi phiên bản Windows SDK thành phiên bản được cài đặt mới nhất và bộ công cụ nền tảng thành phiên bản mới nhất. Nếu bạn bỏ lỡ cửa sổ này, bạn có thể nhấp chuột phải vào Giải pháp trong cửa sổ Giải pháp và Dự án và nhấp vào Giải pháp nhắm mục tiêu lại

Khi quá trình này hoàn tất, bạn cần tải xuống một số tệp nguồn để có thể xây dựng toàn bộ gói CPython. Bên trong thư mục

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
107 có tệp
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
108 tự động hóa việc này cho bạn. Mở lời nhắc dòng lệnh bên trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
107 đã tải xuống và chạy
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
110

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
4

Tiếp theo, quay lại trong Visual Studio, xây dựng CPython bằng cách nhấn Ctrl + Shift +B, or choosing Build Solution from the top menu. If you receive any errors about the Windows SDK being missing, make sure you set the right targeting settings in the Retarget Solution window. You should also see Windows Kits inside your Start Menu, and Windows Software Development Kit inside of that menu.

Giai đoạn xây dựng lần đầu tiên có thể mất 10 phút hoặc hơn. Sau khi quá trình xây dựng hoàn tất, bạn có thể thấy một vài cảnh báo mà bạn có thể bỏ qua và cuối cùng sẽ hoàn tất

Để bắt đầu phiên bản gỡ lỗi của CPython, hãy nhấn F5 và CPython sẽ bắt đầu ở chế độ Gỡ lỗi thẳng vào REPL.

Khi quá trình này hoàn tất, bạn có thể chạy bản dựng Phát hành bằng cách thay đổi cấu hình bản dựng từ Gỡ lỗi thành Phát hành trên thanh menu trên cùng và chạy lại Giải pháp bản dựng một lần nữa. Bây giờ bạn có cả phiên bản Gỡ lỗi và Phát hành của tệp nhị phân CPython trong vòng

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
111

Bạn có thể thiết lập Visual Studio để có thể mở REPL bằng bản dựng Phát hành hoặc Gỡ lỗi bằng cách chọn

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
112->
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
113->
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
114 từ menu trên cùng

Sau đó nhấp vào Thêm môi trường và sau đó nhắm mục tiêu nhị phân Gỡ lỗi hoặc Phát hành. Nhị phân gỡ lỗi sẽ kết thúc bằng

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
115, ví dụ:
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
116 và
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
117. Rất có thể bạn sẽ muốn sử dụng tệp nhị phân gỡ lỗi vì nó đi kèm với hỗ trợ Gỡ lỗi trong Visual Studio và sẽ hữu ích cho hướng dẫn này

Trong cửa sổ Thêm môi trường, nhắm mục tiêu tệp

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
116 làm trình thông dịch bên trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
119 và
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
117 làm trình thông dịch cửa sổ

Bây giờ, bạn có thể bắt đầu phiên REPL bằng cách nhấp vào Mở cửa sổ tương tác trong cửa sổ Môi trường Python và bạn sẽ thấy REPL cho phiên bản Python đã biên dịch

Trong hướng dẫn này sẽ có các phiên REPL với các lệnh ví dụ. Tôi khuyến khích bạn sử dụng nhị phân Gỡ lỗi để chạy các phiên REPL này trong trường hợp bạn muốn đặt bất kỳ điểm dừng nào trong mã

Cuối cùng, để điều hướng mã dễ dàng hơn, trong Chế độ xem giải pháp, hãy nhấp vào nút chuyển đổi bên cạnh biểu tượng Trang chủ để chuyển sang chế độ xem Thư mục

Bây giờ bạn đã có một phiên bản CPython được biên dịch và sẵn sàng hoạt động, hãy cùng tìm hiểu cách thức hoạt động của trình biên dịch CPython

Loại bỏ các quảng cáo

Trình biên dịch làm gì?

Mục đích của trình biên dịch là chuyển đổi ngôn ngữ này sang ngôn ngữ khác. Hãy nghĩ về một trình biên dịch giống như một dịch giả. Bạn sẽ thuê một người phiên dịch để nghe bạn nói tiếng Anh và sau đó nói bằng tiếng Nhật

Một số trình biên dịch sẽ biên dịch thành mã máy cấp thấp có thể được thực thi trực tiếp trên hệ thống. Các trình biên dịch khác sẽ biên dịch thành một ngôn ngữ trung gian, được thực thi bởi một máy ảo

Một quyết định quan trọng cần đưa ra khi chọn trình biên dịch là các yêu cầu về tính di động của hệ thống. Java và. NET CLR sẽ biên dịch thành Ngôn ngữ trung gian để mã được biên dịch có thể di chuyển trên nhiều kiến ​​trúc hệ thống. C, Go, C++ và Pascal sẽ biên dịch thành một tệp thực thi cấp thấp sẽ chỉ hoạt động trên các hệ thống tương tự như hệ thống được biên dịch

Vì các ứng dụng Python thường được phân phối dưới dạng mã nguồn nên vai trò của bộ thực thi Python là chuyển đổi mã nguồn Python và thực thi nó trong một bước. Trong nội bộ, thời gian chạy CPython sẽ biên dịch mã của bạn. Một quan niệm sai lầm phổ biến là Python là một ngôn ngữ thông dịch. Nó thực sự được tổng hợp

Mã Python không được biên dịch thành mã máy. Nó được biên dịch thành một ngôn ngữ trung gian cấp thấp đặc biệt gọi là bytecode mà chỉ CPython mới hiểu được. Mã này được lưu trữ trong các tệp

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
121 trong một thư mục ẩn và được lưu vào bộ đệm để thực thi. Nếu bạn chạy cùng một ứng dụng Python hai lần mà không thay đổi mã nguồn, lần thứ hai sẽ luôn nhanh hơn nhiều. Điều này là do nó tải bytecode đã biên dịch và thực thi trực tiếp

Tại sao CPython được viết bằng C mà không phải Python?

Chữ C trong CPython là tham chiếu đến ngôn ngữ lập trình C, ngụ ý rằng bản phân phối Python này được viết bằng ngôn ngữ C

Tuyên bố này phần lớn là sự thật. trình biên dịch trong CPython được viết bằng C thuần túy. Tuy nhiên, nhiều mô-đun thư viện tiêu chuẩn được viết bằng Python thuần túy hoặc kết hợp giữa C và Python

Vậy tại sao CPython được viết bằng C mà không phải Python?

Câu trả lời nằm ở cách trình biên dịch hoạt động. Có hai loại trình biên dịch

  1. Trình biên dịch tự lưu trữ là trình biên dịch được viết bằng ngôn ngữ mà chúng biên dịch, chẳng hạn như trình biên dịch Go
  2. Trình biên dịch nguồn-đến-nguồn là trình biên dịch được viết bằng ngôn ngữ khác đã có sẵn trình biên dịch

Nếu bạn đang viết một ngôn ngữ lập trình mới từ đầu, bạn cần một ứng dụng thực thi để biên dịch trình biên dịch của mình. Bạn cần một trình biên dịch để thực thi mọi thứ, vì vậy khi các ngôn ngữ mới được phát triển, chúng thường được viết trước bằng một ngôn ngữ cũ hơn, lâu đời hơn

Một ví dụ điển hình là ngôn ngữ lập trình Go. Trình biên dịch Go đầu tiên được viết bằng C, sau đó khi Go có thể được biên dịch, trình biên dịch được viết lại bằng Go

CPython giữ di sản C của nó. nhiều mô-đun thư viện tiêu chuẩn, như mô-đun

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
122 hoặc mô-đun
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
123, được viết bằng C để truy cập API hệ điều hành cấp thấp. Các API trong nhân Windows và Linux để tạo ổ cắm mạng, làm việc với hệ thống tệp hoặc tương tác với màn hình đều được viết bằng C. Thật hợp lý khi lớp mở rộng của Python được tập trung vào ngôn ngữ C. Ở phần sau của bài viết này, chúng ta sẽ đề cập đến Thư viện chuẩn Python và các mô-đun C

Có một trình biên dịch Python được viết bằng Python gọi là PyPy. Logo của PyPy là một Ouroboros để thể hiện bản chất tự lưu trữ của trình biên dịch

Một ví dụ khác về trình biên dịch chéo cho Python là Jython. Jython được viết bằng Java và biên dịch từ mã nguồn Python thành Java bytecode. Cũng giống như cách CPython giúp dễ dàng nhập các thư viện C và sử dụng chúng từ Python, Jython giúp dễ dàng nhập và tham chiếu các mô-đun và lớp Java

Đặc tả ngôn ngữ Python

Chứa trong mã nguồn CPython là định nghĩa của ngôn ngữ Python. Đây là đặc tả tham chiếu được sử dụng bởi tất cả các trình thông dịch Python

Thông số kỹ thuật ở cả định dạng người đọc được và máy đọc được. Bên trong tài liệu là giải thích chi tiết về ngôn ngữ Python, những gì được phép và cách mỗi câu lệnh nên hoạt động

Tài liệu

Nằm bên trong thư mục

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
124 là các giải thích về reStructuredText của từng tính năng trong ngôn ngữ Python. Điều này tạo thành hướng dẫn tham khảo Python chính thức trên tài liệu. con trăn. tổ chức

Bên trong thư mục là các tệp bạn cần hiểu toàn bộ ngôn ngữ, cấu trúc và từ khóa

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
5

Bên trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
125, tài liệu về câu lệnh ghép, bạn có thể xem một ví dụ đơn giản xác định câu lệnh
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
126

Câu lệnh

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
126 có thể được sử dụng theo nhiều cách trong Python, cách đơn giản nhất là khởi tạo trình quản lý ngữ cảnh và khối mã lồng nhau

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
6

Bạn có thể gán kết quả cho một biến bằng cách sử dụng từ khóa

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
128

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
7

Bạn cũng có thể xâu chuỗi các trình quản lý ngữ cảnh cùng với dấu phẩy

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
8

Tiếp theo, chúng ta sẽ khám phá tài liệu có thể đọc được trên máy tính của ngôn ngữ Python

Văn phạm

Tài liệu chứa thông số kỹ thuật mà con người có thể đọc được của ngôn ngữ và thông số kỹ thuật mà máy có thể đọc được nằm trong một tệp duy nhất,

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
129

Tệp ngữ pháp được viết bằng ký hiệu ngữ cảnh có tên là Biểu mẫu Backus-Naur [BNF]. BNF không dành riêng cho Python và thường được sử dụng làm ký hiệu cho ngữ pháp trong nhiều ngôn ngữ khác

Khái niệm về cấu trúc ngữ pháp trong ngôn ngữ lập trình được lấy cảm hứng từ tác phẩm của Noam Chomsky về Cấu trúc cú pháp vào những năm 1950

Tệp ngữ pháp của Python sử dụng đặc tả BNF mở rộng [EBNF] với cú pháp biểu thức chính quy. Vì vậy, trong tệp ngữ pháp bạn có thể sử dụng

  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    130 để lặp lại
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    131 để lặp lại ít nhất một lần
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    59 cho các bộ phận tùy chọn
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    133 cho các lựa chọn thay thế
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    134 để nhóm

Nếu bạn tìm kiếm câu lệnh

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
126 trong tệp ngữ pháp, ở khoảng dòng 80, bạn sẽ thấy các định nghĩa cho câu lệnh
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
126

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
9

Bất cứ điều gì trong dấu ngoặc kép là một chuỗi ký tự, đó là cách từ khóa được xác định. Vì vậy,

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
137 được chỉ định là

  1. Bắt đầu bằng từ
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    126
  2. Tiếp theo là một
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    139, đó là một
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    140 và [tùy chọn], từ
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    128, và một biểu thức
  3. Theo dõi một hoặc nhiều mục, mỗi mục được phân tách bằng dấu phẩy
  4. Kết thúc bằng một
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    142
  5. Theo sau là một
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    143

Có tham chiếu đến một số định nghĩa khác trong hai dòng này

  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    143 đề cập đến một khối mã có một hoặc nhiều câu lệnh
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    140 đề cập đến một tuyên bố đơn giản được đánh giá
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    146 đề cập đến một biểu thức đơn giản

Nếu bạn muốn khám phá những điều đó một cách chi tiết, toàn bộ ngữ pháp Python được định nghĩa trong tệp duy nhất này

Nếu bạn muốn xem một ví dụ gần đây về cách sử dụng ngữ pháp, trong PEP 572, toán tử dấu hai chấm bằng đã được thêm vào tệp ngữ pháp trong

Sử dụng
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
147

Bản thân tệp ngữ pháp không bao giờ được sử dụng bởi trình biên dịch Python. Thay vào đó, một bảng phân tích cú pháp được tạo bởi một công cụ có tên là

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
147 được sử dụng.
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
147 đọc tệp ngữ pháp và chuyển đổi nó thành bảng phân tích cú pháp. Nếu bạn thay đổi tệp ngữ pháp, bạn phải tạo lại bảng phân tích cú pháp và biên dịch lại Python

Ghi chú. Ứng dụng

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
147 được viết lại bằng Python 3. 8 từ C đến Python thuần túy

Để xem hoạt động của

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
147, hãy thay đổi một phần ngữ pháp Python. Xung quanh dòng 51, bạn sẽ thấy định nghĩa của câu lệnh
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
152

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
10

Thay đổi dòng đó để chấp nhận từ khóa

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
153 hoặc
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
154 làm từ khóa

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
11

Bây giờ bạn cần xây dựng lại các tệp ngữ pháp. Trên macOS và Linux, hãy chạy

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
155 để chạy
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
147 trên tệp ngữ pháp đã thay đổi. Đối với Windows, không có cách nào được hỗ trợ chính thức để chạy
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
147. Tuy nhiên, bạn có thể sao chép ngã ba của tôi và chạy
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
158 từ trong thư mục
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
107

Bạn sẽ thấy một kết quả tương tự như thế này, cho biết rằng các tệp

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
160 và
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
161 mới đã được tạo

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
12

Ghi chú.

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
147 hoạt động bằng cách chuyển đổi các câu lệnh EBNF thành Máy tự động hữu hạn không xác định [NFA], sau đó được chuyển thành Máy tự động hữu hạn xác định [DFA]. DFA được trình phân tích cú pháp sử dụng làm bảng phân tích cú pháp theo cách đặc biệt chỉ dành cho CPython. Kỹ thuật này được hình thành tại Đại học Stanford và phát triển vào những năm 1980, ngay trước khi Python ra đời

Với các bảng phân tích cú pháp được tạo lại, bạn cần biên dịch lại CPython để xem cú pháp mới. Sử dụng các bước biên dịch giống như bạn đã sử dụng trước đó cho hệ điều hành của mình

Nếu mã được biên dịch thành công, bạn có thể thực thi mã nhị phân CPython mới của mình và bắt đầu REPL

Trong REPL, bây giờ bạn có thể thử định nghĩa một hàm và thay vì sử dụng câu lệnh

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
152, hãy sử dụng từ khóa thay thế
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
164 mà bạn đã biên dịch thành ngữ pháp Python

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
13

Tốt lắm. Bạn đã thay đổi cú pháp CPython và biên dịch phiên bản CPython của riêng bạn. vận chuyển nó

Tiếp theo, chúng ta sẽ khám phá các mã thông báo và mối quan hệ của chúng với ngữ pháp

mã thông báo

Bên cạnh tệp ngữ pháp trong thư mục

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
165 là tệp
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
166, chứa từng loại duy nhất được tìm thấy dưới dạng nút lá trong cây phân tích cú pháp. Chúng tôi sẽ đề cập sâu về cây phân tích cú pháp sau. Mỗi mã thông báo cũng có một tên và một ID duy nhất được tạo. Tên được sử dụng để làm cho nó đơn giản hơn để tham khảo trong mã thông báo

Ghi chú. Tệp

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
166 là một tính năng mới trong Python 3. 8

Ví dụ: dấu ngoặc đơn bên trái được gọi là

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
168 và dấu chấm phẩy được gọi là
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
169. Bạn sẽ thấy những mã thông báo này sau trong bài viết

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
14

Cũng như file

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
165, nếu thay đổi file
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
166 thì bạn cần chạy lại
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
147

Để xem mã thông báo đang hoạt động, bạn có thể sử dụng mô-đun ________ 1173 trong Python. Tạo một tập lệnh Python đơn giản có tên là

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
174

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
15

Đối với phần còn lại của hướng dẫn này,

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
175 sẽ đề cập đến phiên bản đã biên dịch của CPython. Tuy nhiên, lệnh thực tế sẽ phụ thuộc vào hệ thống của bạn

Cho cửa sổ

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
16

cho Linux

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
17

Đối với macOS

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
18

Sau đó chuyển tệp này qua một mô-đun được tích hợp trong thư viện chuẩn có tên là

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
173. Bạn sẽ thấy danh sách mã thông báo, theo dòng và ký tự. Sử dụng cờ
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
177 để xuất tên mã thông báo chính xác

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
19

Ở đầu ra, cột đầu tiên là phạm vi của tọa độ dòng/cột, cột thứ hai là tên của mã thông báo và cột cuối cùng là giá trị của mã thông báo

Ở đầu ra, mô-đun

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
173 đã ngụ ý một số mã thông báo không có trong tệp. Mã thông báo
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
179 cho
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
180 và một dòng trống ở cuối, cung cấp cho
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
181 để đóng phần khai báo hàm và một
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
182 để kết thúc tệp

Cách tốt nhất là có một dòng trống ở cuối tệp nguồn Python của bạn. Nếu bạn bỏ qua nó, CPython sẽ thêm nó cho bạn, với một hình phạt nhỏ về hiệu suất

Mô-đun

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
173 được viết bằng Python thuần túy và nằm ở
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
184 trong mã nguồn CPython

Quan trọng. Có hai mã thông báo trong mã nguồn CPython. một cái được viết bằng Python, được trình bày ở đây và một cái khác được viết bằng C. Mã thông báo được viết bằng Python có nghĩa là một tiện ích và mã được viết bằng C được sử dụng bởi trình biên dịch Python. Họ có đầu ra và hành vi giống hệt nhau. Phiên bản viết bằng C được thiết kế để thực hiện và mô-đun bằng Python được thiết kế để gỡ lỗi

Để xem phần đọc chi tiết của mã thông báo C, bạn có thể chạy Python với cờ

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
185. Sử dụng tập lệnh
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
174 mà bạn đã tạo trước đó, hãy chạy tập lệnh đó như sau

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
30

Trong kết quả, bạn có thể thấy rằng nó đánh dấu

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
164 như một từ khóa. Trong chương tiếp theo, chúng ta sẽ xem cách thực thi mã nhị phân Python đến mã thông báo và điều gì xảy ra từ đó để thực thi mã của bạn

Bây giờ bạn đã có cái nhìn tổng quan về ngữ pháp Python và mối quan hệ giữa mã thông báo và câu lệnh, có một cách để chuyển đổi đầu ra

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
147 thành biểu đồ tương tác

Đây là một ảnh chụp màn hình của Python 3. ngữ văn 8a2

Gói Python được sử dụng để tạo biểu đồ này,

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
189, sẽ được trình bày trong chương sau

Loại bỏ các quảng cáo

Quản lý bộ nhớ trong CPython

Xuyên suốt bài viết này, bạn sẽ thấy các tham chiếu đến một đối tượng. Đấu trường là một trong những cấu trúc quản lý bộ nhớ của CPython. Mã nằm trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
191 và chứa một trình bao bọc xung quanh các chức năng cấp phát và hủy cấp phát bộ nhớ của C

Trong chương trình C được viết theo cách truyền thống, nhà phát triển nên cấp phát bộ nhớ cho cấu trúc dữ liệu trước khi ghi vào dữ liệu đó. Việc phân bổ này đánh dấu bộ nhớ thuộc về tiến trình với hệ điều hành

Nhà phát triển cũng có thể giải phóng hoặc “giải phóng” bộ nhớ đã cấp phát khi bộ nhớ không còn được sử dụng nữa và đưa nó trở lại bảng khối bộ nhớ trống của hệ điều hành. Nếu một quá trình phân bổ bộ nhớ cho một biến, chẳng hạn như trong một hàm hoặc vòng lặp, khi chức năng đó hoàn thành, bộ nhớ sẽ không tự động được trả lại cho hệ điều hành trong C. Vì vậy, nếu nó không được giải phóng rõ ràng trong mã C, nó sẽ gây rò rỉ bộ nhớ. Quá trình này sẽ tiếp tục chiếm nhiều bộ nhớ hơn mỗi khi chức năng đó chạy cho đến khi hệ thống hết bộ nhớ và gặp sự cố

Python nhận trách nhiệm đó từ lập trình viên và sử dụng hai thuật toán. bộ đếm tham chiếu và bộ thu gom rác

Bất cứ khi nào trình thông dịch được khởi tạo, a được tạo và đính kèm một trong các trường trong trình thông dịch. Trong vòng đời của trình thông dịch CPython, nhiều đấu trường có thể được phân bổ. Chúng được kết nối với một danh sách được liên kết. Đấu trường lưu trữ danh sách các con trỏ tới Đối tượng Python dưới dạng

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
193. Bất cứ khi nào một đối tượng Python mới được tạo, một con trỏ tới nó sẽ được thêm vào bằng cách sử dụng. Cuộc gọi chức năng này lưu trữ một con trỏ trong danh sách đấu trường,
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
195

Mặc dù Python không có con trỏ nhưng vẫn có một số kỹ thuật thú vị để mô phỏng hành vi của con trỏ

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
190 phục vụ chức năng thứ hai, đó là phân bổ và tham chiếu danh sách các khối bộ nhớ thô. Ví dụ: một
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
197 sẽ cần thêm bộ nhớ nếu bạn thêm hàng nghìn giá trị bổ sung. Mã C của đối tượng
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
197 không cấp phát bộ nhớ trực tiếp. Đối tượng nhận các khối bộ nhớ thô từ
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
190 bằng cách gọi từ
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
301 với kích thước bộ nhớ được yêu cầu. Nhiệm vụ này được hoàn thành bởi một trừu tượng khác trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
302. Trong mô-đun cấp phát đối tượng, bộ nhớ có thể được cấp phát, giải phóng và cấp phát lại cho Đối tượng Python

Một danh sách liên kết của các khối được phân bổ được lưu trữ bên trong đấu trường, để khi một trình thông dịch bị dừng, tất cả các khối bộ nhớ được quản lý có thể được giải phóng trong một lần sử dụng

Lấy ví dụ về

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
193. Nếu bạn đã
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
305 một đối tượng vào cuối danh sách Python, bạn không cần phải phân bổ lại bộ nhớ được sử dụng trong danh sách hiện có trước đó. Phương thức
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
305 gọi xử lý cấp phát bộ nhớ cho danh sách. Mỗi đối tượng danh sách giữ một danh sách dung lượng bộ nhớ được phân bổ. Nếu mục bạn đang thêm vào vừa với bộ nhớ trống hiện có, mục đó sẽ được thêm vào một cách đơn giản. Nếu danh sách cần thêm dung lượng bộ nhớ, nó sẽ được mở rộng. Danh sách được mở rộng theo độ dài 0, 4, 8, 16, 25, 35, 46, 58, 72, 88

được gọi để mở rộng bộ nhớ được phân bổ trong danh sách. là một trình bao bọc API cho

Python cũng có một trình bao bọc đặc biệt cho lệnh gọi C

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
311, đặt kích thước tối đa của cấp phát bộ nhớ để giúp ngăn lỗi tràn bộ đệm [Xem phần ]

Tóm tắt

  • Việc phân bổ các khối bộ nhớ thô được thực hiện thông qua
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    313
  • Các con trỏ tới các đối tượng Python được lưu trữ trong
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    190
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    190 cũng lưu trữ danh sách liên kết của các khối bộ nhớ được cấp phát

Thông tin thêm về API được trình bày chi tiết trên tài liệu CPython

Đếm tham chiếu

Để tạo một biến trong Python, bạn phải gán một giá trị cho một biến được đặt tên duy nhất

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
31

Bất cứ khi nào một giá trị được gán cho một biến trong Python, tên của biến đó sẽ được kiểm tra trong phạm vi cục bộ và toàn cục để xem nó đã tồn tại chưa

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
316 chưa có trong từ điển
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
317 hoặc
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
318 nên đối tượng mới này được tạo và giá trị được gán là hằng số
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
319

Hiện tại có một tham chiếu đến

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
316, vì vậy bộ đếm tham chiếu cho
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
316 được tăng thêm 1

Bạn sẽ thấy các lệnh gọi hàm và trong toàn bộ mã nguồn C cho CPython. Các hàm này tăng và giảm số lượng tham chiếu đến đối tượng đó

Các tham chiếu đến một đối tượng bị giảm khi một biến nằm ngoài phạm vi mà nó được khai báo. Phạm vi trong Python có thể đề cập đến một hàm hoặc phương thức, mức hiểu hoặc hàm lambda. Đây là một số phạm vi theo nghĩa đen hơn, nhưng có nhiều phạm vi ngầm định khác, chẳng hạn như truyền biến cho lệnh gọi hàm

Việc xử lý các tham chiếu tăng và giảm dựa trên ngôn ngữ được tích hợp trong trình biên dịch CPython và vòng lặp thực thi lõi,

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
324, mà chúng tôi sẽ đề cập chi tiết ở phần sau của bài viết này

Bất cứ khi nào

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
323 được gọi và bộ đếm trở thành 0, hàm được gọi. Đối với đối tượng đó được gọi cho tất cả bộ nhớ đã được cấp phát

Thu gom rác thải

Bao lâu thì rác của bạn được thu gom?

Khi bạn làm xong việc gì đó, bạn vứt bỏ nó và ném vào thùng rác. Nhưng thùng rác đó sẽ không được thu gom ngay lập tức. Bạn cần đợi xe rác đến và lấy nó

CPython có nguyên tắc tương tự, sử dụng thuật toán thu gom rác. Trình thu gom rác của CPython được bật theo mặc định, diễn ra trong nền và hoạt động để giải phóng bộ nhớ đã được sử dụng cho các đối tượng không còn được sử dụng

Vì thuật toán thu gom rác phức tạp hơn nhiều so với bộ đếm tham chiếu, nên nó không xảy ra mọi lúc, nếu không, nó sẽ tiêu tốn một lượng lớn tài nguyên CPU. Nó xảy ra định kỳ, sau một số hoạt động nhất định

Thư viện chuẩn của CPython đi kèm với một mô-đun Python để giao tiếp với đấu trường và trình thu gom rác, mô-đun

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
328. Đây là cách sử dụng mô-đun
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
328 ở chế độ gỡ lỗi

>>>

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
32

Điều này sẽ in số liệu thống kê bất cứ khi nào bộ thu gom rác được chạy

Bạn có thể lấy ngưỡng mà sau đó bộ thu gom rác được chạy bằng cách gọi

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
330

>>>

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
33

Bạn cũng có thể nhận được số lượng ngưỡng hiện tại

>>>

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
34

Cuối cùng, bạn có thể chạy thủ công thuật toán thu thập

>>>

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
35

Điều này sẽ gọi bên trong tệp

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
332 chứa việc triển khai thuật toán thu gom rác

Loại bỏ các quảng cáo

Phần kết luận

Trong Phần 1, bạn đã trình bày về cấu trúc của kho mã nguồn, cách biên dịch từ nguồn và đặc tả ngôn ngữ Python. Những khái niệm cốt lõi này sẽ rất quan trọng trong Phần 2 khi bạn tìm hiểu sâu hơn về quy trình phiên dịch Python

Phần 2. Quy trình phiên dịch Python

Bây giờ bạn đã xem phần quản lý bộ nhớ và ngữ pháp Python, bạn có thể làm theo quy trình từ cách nhập

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
57 đến phần mã của bạn được thực thi

Có năm cách nhị phân

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
57 có thể được gọi

  1. Để chạy một lệnh duy nhất với
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    335 và lệnh Python
  2. Để bắt đầu một mô-đun với
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    336 và tên của một mô-đun
  3. Để chạy một tệp có tên tệp
  4. Để chạy đầu vào
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    337 bằng shell pipe
  5. Để bắt đầu REPL và thực hiện từng lệnh một

Python có rất nhiều cách để thực thi các tập lệnh, nó có thể hơi quá sức. Darren Jones đã tổng hợp một khóa học tuyệt vời về cách chạy các tập lệnh Python nếu bạn muốn tìm hiểu thêm

Ba tệp nguồn bạn cần kiểm tra để xem quy trình này là

  1. cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    338 là một điểm vào đơn giản
  2. cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    339 chứa mã để tập hợp toàn bộ quá trình, tải cấu hình, thực thi mã và xóa bộ nhớ
  3. cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    340 tải cấu hình từ môi trường hệ thống và hợp nhất nó với bất kỳ cờ dòng lệnh nào

Sơ đồ này cho thấy mỗi chức năng đó được gọi như thế nào

Chế độ thực thi được xác định từ cấu hình

Kiểu mã nguồn CPython

Tương tự như hướng dẫn kiểu PEP8 cho mã Python, có một hướng dẫn kiểu chính thức cho mã CPython C, được thiết kế ban đầu vào năm 2001 và được cập nhật cho các phiên bản hiện đại

Có một số tiêu chuẩn đặt tên giúp ích khi điều hướng mã nguồn

  • Sử dụng tiền tố

    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    341 cho các hàm công khai, không bao giờ cho các hàm tĩnh. Tiền tố
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    342 được dành riêng cho các thói quen dịch vụ toàn cầu như
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    343. Các nhóm quy trình cụ thể [như API loại đối tượng cụ thể] sử dụng tiền tố dài hơn, chẳng hạn như
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    344 cho các hàm chuỗi

  • Các hàm và biến công khai sử dụng MixedCase với dấu gạch dưới, như thế này. , ,

    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    347

  • Đôi khi, một chức năng "nội bộ" phải được hiển thị cho trình tải. Chúng tôi sử dụng tiền tố

    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    348 cho điều này, ví dụ:

  • Macro phải có tiền tố MixedCase và sau đó sử dụng chữ hoa, ví dụ:

    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    350,
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    351

Thiết lập cấu hình thời gian chạy

Trong các đường bơi, bạn có thể thấy rằng trước khi bất kỳ mã Python nào được thực thi, bộ thực thi trước tiên sẽ thiết lập cấu hình. Cấu hình của thời gian chạy là cấu trúc dữ liệu được xác định trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
352 có tên

Cấu trúc dữ liệu cấu hình bao gồm những thứ như

  • Cờ thời gian chạy cho các chế độ khác nhau như chế độ gỡ lỗi và tối ưu hóa
  • Chế độ thực thi, chẳng hạn như tên tệp đã được chuyển chưa,
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    337 đã được cung cấp hay tên mô-đun
  • Tùy chọn mở rộng, được chỉ định bởi
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    355
  • Biến môi trường cho cài đặt thời gian chạy

Dữ liệu cấu hình chủ yếu được sử dụng bởi thời gian chạy CPython để bật và tắt các tính năng khác nhau

Python cũng đi kèm với một số Tùy chọn Giao diện Dòng lệnh. Trong Python, bạn có thể bật chế độ dài dòng bằng cờ

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
356. Ở chế độ dài dòng, Python sẽ in thông báo ra màn hình khi các mô-đun được tải

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
36

Bạn sẽ thấy hàng trăm dòng trở lên với tất cả các lần nhập gói trang web người dùng của bạn và bất kỳ thứ gì khác trong môi trường hệ thống

Bạn có thể xem định nghĩa của cờ này trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
352 bên trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
358 cho

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
37

Trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
340, logic để đọc cài đặt từ các biến môi trường và cờ dòng lệnh thời gian chạy được thiết lập

Trong hàm

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
361, các biến môi trường được đọc và sử dụng để gán giá trị cho cài đặt cấu hình

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
38

Đối với cài đặt dài dòng, bạn có thể thấy rằng giá trị của

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
362 được sử dụng để đặt giá trị của
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
363, nếu tìm thấy
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
362. Nếu biến môi trường không tồn tại thì giá trị mặc định của
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
365 sẽ được giữ nguyên

Sau đó, trong vòng

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
367 một lần nữa, cờ dòng lệnh được sử dụng để đặt giá trị, nếu được cung cấp

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
39

Giá trị này sau đó được sao chép vào biến toàn cục

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
368 bởi hàm

Trong phiên Python, bạn có thể truy cập các cờ thời gian chạy, như chế độ dài dòng, chế độ im lặng, sử dụng bộ dữ liệu có tên

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
370. Các cờ
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
371 đều có sẵn trong từ điển
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
372

>>>

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
60

Ngoài cấu hình thời gian chạy trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
373, còn có cấu hình bản dựng nằm bên trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
374 trong thư mục gốc. Tệp này được tạo động trong bước
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
67 trong quy trình xây dựng hoặc bởi Visual Studio cho các hệ thống Windows

Bạn có thể xem cấu hình bản dựng bằng cách chạy

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
61

Loại bỏ các quảng cáo

Đọc tệp/Đầu vào

Khi CPython có cấu hình thời gian chạy và các đối số dòng lệnh, nó có thể thiết lập những gì nó cần để thực thi

Nhiệm vụ này được xử lý bởi chức năng bên trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
339. Tùy thuộc vào phiên bản
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
378 mới được tạo, CPython hiện sẽ thực thi mã được cung cấp qua một số tùy chọn

Đầu vào qua
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
335

Đơn giản nhất là cung cấp cho CPython một lệnh với tùy chọn

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
335 và một chương trình Python bên trong dấu ngoặc kép

Ví dụ

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
62

Đây là sơ đồ đầy đủ về cách điều này xảy ra

Đầu tiên, hàm được thực thi bên trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
339 lấy lệnh được truyền trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
335 làm đối số trong kiểu C
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
384. Loại
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
384 thường được sử dụng làm loại lưu trữ cấp thấp cho dữ liệu Unicode trên CPython vì kích thước của loại có thể lưu trữ các ký tự UTF8

Khi chuyển đổi

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
384 thành chuỗi Python, tệp
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
387 có hàm trợ giúp trả về một
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
301, thuộc loại
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
390. Mã hóa thành UTF8 sau đó được thực hiện bởi
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
391 trên đối tượng Python
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
390 để chuyển đổi nó thành đối tượng Python
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
393

Khi điều này hoàn tất, sau đó sẽ chuyển đối tượng byte Python để thực thi, nhưng trước tiên hãy chuyển đổi lại loại

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
393 thành loại
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
390

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
63

Việc chuyển đổi

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
384 sang Unicode, byte, và sau đó là một chuỗi tương đương như sau

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
64

Chức năng này là một phần của

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
600. Mục đích của nó là biến lệnh đơn giản này thành một mô-đun Python và sau đó gửi lệnh đó để được thực thi. Vì một mô-đun Python cần phải có
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
601 để được thực thi dưới dạng một mô-đun độc lập, nên nó sẽ tự động tạo mô-đun đó

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
65

Khi đã tạo một mô-đun và một từ điển, nó sẽ gọi , tạo một tên tệp giả và sau đó gọi trình phân tích cú pháp Python để tạo AST từ chuỗi và trả về một mô-đun,

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
604

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
66

Bạn sẽ đi sâu vào mã AST và Trình phân tích cú pháp trong phần tiếp theo

Đầu vào qua
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
336

Một cách khác để thực thi các lệnh Python là sử dụng tùy chọn

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
336 với tên của một mô-đun. Ví dụ điển hình là
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
607 để chạy module unittest trong thư viện chuẩn

Khả năng thực thi các mô-đun dưới dạng tập lệnh ban đầu được đề xuất trong PEP 338 và sau đó là tiêu chuẩn cho nhập tương đối rõ ràng được xác định trong PEP366

Việc sử dụng cờ

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
336 ngụ ý rằng trong gói mô-đun, bạn muốn thực thi bất cứ thứ gì bên trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
601. Điều đó cũng ngụ ý rằng bạn muốn tìm kiếm mô-đun có tên
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
610

Cơ chế tìm kiếm này là lý do tại sao bạn không cần nhớ nơi lưu trữ mô-đun

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
63 trên hệ thống tệp của mình

Bên trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
339 có một chức năng được gọi khi dòng lệnh được chạy với cờ
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
336. Tên của mô-đun được truyền dưới dạng đối số
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
614

CPython sau đó sẽ nhập một mô-đun thư viện chuẩn,

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
615 và thực thi nó bằng cách sử dụng. Quá trình nhập được thực hiện bằng hàm C API , được tìm thấy trong tệp
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
618

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
67

Trong hàm này, bạn cũng sẽ thấy 2 hàm C API khác. và. Bởi vì trả về một

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
622, loại đối tượng cốt lõi, bạn cần gọi các hàm đặc biệt để lấy các thuộc tính và gọi nó

Trong Python, nếu bạn có một đối tượng và muốn lấy một thuộc tính, thì bạn có thể gọi

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
623. Trong API C, cuộc gọi này là , được tìm thấy trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
625. Nếu bạn muốn chạy một hàm có thể gọi được, bạn sẽ đặt nó trong dấu ngoặc đơn hoặc bạn có thể chạy thuộc tính
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
626 trên bất kỳ đối tượng Python nào. Phương thức
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
626 được triển khai bên trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
625

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
68

Mô-đun

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
615 được viết bằng Python thuần túy và nằm trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
630

Thực thi

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
631 tương đương với chạy
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
632. Mô-đun
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
615 được tạo để trừu tượng hóa quá trình định vị và thực thi các mô-đun trên một hệ điều hành

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
615 thực hiện một số việc để chạy mô-đun đích

  • Các cuộc gọi
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    635 cho tên mô-đun bạn đã cung cấp
  • Đặt
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    636 [tên mô-đun] thành một không gian tên có tên là
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    601
  • Thực thi mô-đun trong không gian tên
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    601

Mô-đun

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
615 cũng hỗ trợ thực thi các thư mục và tệp zip

Nhập thông qua Tên tệp

Nếu đối số đầu tiên của

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
57 là tên tệp, chẳng hạn như
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
641, thì CPython sẽ mở một bộ điều khiển tệp, tương tự như sử dụng
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
642 trong Python và chuyển bộ điều khiển đó vào bên trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
600

Có 3 con đường mà hàm này có thể đi

  1. Nếu đường dẫn tệp là tệp
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    121, nó sẽ gọi
  2. Nếu đường dẫn tệp là tệp script [______1647] thì nó sẽ chạy
  3. Nếu đường dẫn tệp là
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    337 vì người dùng đã chạy
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    650 thì hãy coi
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    337 là phần xử lý tệp và chạy

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
69

Nhập qua Tệp Với
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
648

Đối với

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
337 và các tệp tập lệnh cơ bản, CPython sẽ chuyển phần xử lý tệp đến nằm trong tệp
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
656

Mục đích của tương tự như được sử dụng cho đầu vào

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
335. CPython sẽ tải xử lý tệp vào. Chúng tôi sẽ đề cập đến các mô-đun Trình phân tích cú pháp và AST trong phần tiếp theo. Vì đây là tập lệnh đầy đủ nên không cần bước
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
661 được sử dụng bởi
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
335

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
90

Giống hệt, một khi đã tạo một mô-đun Python từ tệp, nó đã gửi nó để được thực thi

được tìm thấy trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
600 và gửi mô-đun tới AST để được biên dịch thành một đối tượng mã. Các đối tượng mã là một định dạng được sử dụng để lưu trữ các hoạt động mã byte và định dạng được lưu giữ trong các tệp
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
121

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
91

Chúng tôi sẽ đề cập đến trình biên dịch CPython và mã byte trong phần tiếp theo. Cuộc gọi đến là một chức năng bao bọc đơn giản gọi trong tệp

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
671. Hàm này là vòng lặp đánh giá chính cho CPython, nó lặp qua từng câu lệnh mã byte và thực thi nó trên máy cục bộ của bạn

Nhập thông qua Bytecode đã biên dịch với
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
646

Trong đó có một mệnh đề dành cho người dùng cung cấp đường dẫn tệp đến tệp

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
121. Nếu đường dẫn tệp kết thúc bằng
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
121 thì thay vì tải tệp dưới dạng tệp văn bản thuần túy và phân tích cú pháp, nó sẽ giả định rằng tệp
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
121 chứa một đối tượng mã được ghi vào đĩa

Hàm bên trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
600 sau đó sắp xếp đối tượng mã từ tệp
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
121 bằng cách sử dụng trình xử lý tệp. Marshaling là thuật ngữ kỹ thuật để sao chép nội dung của tệp vào bộ nhớ và chuyển đổi chúng thành cấu trúc dữ liệu cụ thể. Cấu trúc dữ liệu đối tượng mã trên đĩa là cách trình biên dịch CPython lưu vào bộ đệm mã đã biên dịch để nó không cần phân tích cú pháp mỗi khi tập lệnh được gọi

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
92

Khi đối tượng mã đã được sắp xếp theo thứ tự vào bộ nhớ, nó sẽ được gửi tới , lệnh này sẽ gọi

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
682 để thực thi mã

Loại bỏ các quảng cáo

Từ vựng và phân tích cú pháp

Trong quá trình khám phá cách đọc và thực thi các tệp Python, chúng tôi đã tìm hiểu sâu về trình phân tích cú pháp và các mô-đun AST, với các lệnh gọi hàm tới

Gắn bó với

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
600, hàm sẽ lấy một tệp xử lý, cờ trình biên dịch và một thể hiện
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
190 và chuyển đổi đối tượng tệp thành đối tượng nút bằng cách sử dụng

Với đối tượng nút, sau đó nó sẽ chuyển đổi nó thành một mô-đun bằng hàm AST

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
93

Vì chúng tôi chuyển sang

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
690 và giai đoạn trình phân tích cú pháp mã thông báo của trình thông dịch CPython. Chức năng này có hai nhiệm vụ quan trọng

  1. Khởi tạo trạng thái mã thông báo bằng cách sử dụng trong
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    693
  2. Chuyển đổi mã thông báo thành cây phân tích cú pháp cụ thể [danh sách
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    694] bằng cách sử dụng trong
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    690

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
94

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
691 [được định nghĩa trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
698] là cấu trúc dữ liệu để lưu trữ tất cả dữ liệu tạm thời được tạo bởi tokenizer. Nó được trả về bộ phân tích cú pháp mã thông báo vì cấu trúc dữ liệu được yêu cầu để phát triển cây cú pháp cụ thể

Bên trong, nó sẽ sử dụng cấu trúc

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
691 và thực hiện các cuộc gọi đến trong một vòng lặp cho đến khi hết tệp và không thể tìm thấy thêm mã thông báo nào nữa

, được định nghĩa trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
693 hoạt động giống như một trình vòng lặp. Nó sẽ tiếp tục trả lại mã thông báo tiếp theo trong cây phân tích cú pháp

là một trong những chức năng phức tạp nhất trong toàn bộ cơ sở mã CPython. Nó có hơn 640 dòng và bao gồm nhiều thập kỷ di sản với các trường hợp cạnh, các tính năng ngôn ngữ mới và cú pháp

Một trong những ví dụ đơn giản hơn sẽ là phần chuyển đổi ngắt dòng mới thành mã thông báo NEWLINE

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
95

Trong trường hợp này,

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
906 là mã thông báo, với giá trị được xác định trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
907. Tất cả các mã thông báo là các giá trị
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
908 không đổi và tệp
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
907 đã được tạo trước đó khi chúng tôi chạy
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
155

Loại

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
694 được trả về sẽ rất cần thiết cho giai đoạn tiếp theo, chuyển đổi cây phân tích cú pháp thành Cây cú pháp trừu tượng [AST]

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
96

Vì CST là một cây cú pháp, ID mã thông báo và ký hiệu nên trình biên dịch sẽ khó đưa ra quyết định nhanh chóng dựa trên ngôn ngữ Python

Đó là lý do tại sao giai đoạn tiếp theo là chuyển đổi CST thành AST, một cấu trúc cấp cao hơn nhiều. Nhiệm vụ này được thực hiện bởi mô-đun

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
913, có cả API C và Python

Trước khi bạn chuyển sang AST, có một cách để truy cập đầu ra từ giai đoạn trình phân tích cú pháp. CPython có một mô-đun thư viện tiêu chuẩn

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
914, hiển thị các hàm C bằng API Python

Mô-đun được ghi lại dưới dạng chi tiết triển khai của CPython để bạn không thấy nó trong các trình thông dịch Python khác. Ngoài ra, đầu ra từ các chức năng không dễ đọc

Đầu ra sẽ ở dạng số, sử dụng mã thông báo và số ký hiệu được tạo bởi giai đoạn

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
155, được lưu trữ trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
907

>>>

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
97

Để dễ hiểu hơn, bạn có thể lấy tất cả các số trong mô-đun

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
917 và
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
918, đặt chúng vào từ điển và thay thế đệ quy các giá trị trong đầu ra của
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
919 bằng tên

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
98

Bạn có thể chạy

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
920 với một biểu thức đơn giản, chẳng hạn như
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
921 để xem cách biểu diễn này dưới dạng cây phân tích cú pháp

>>>

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
99

Ở đầu ra, bạn có thể thấy các ký hiệu viết thường, chẳng hạn như ________ 1922 và các mã thông báo viết hoa, chẳng hạn như ________ 1923

Loại bỏ các quảng cáo

Cây cú pháp trừu tượng

Giai đoạn tiếp theo trong trình thông dịch CPython là chuyển đổi CST do trình phân tích cú pháp tạo ra thành thứ gì đó hợp lý hơn để có thể thực thi. Cấu trúc là một biểu diễn cấp cao hơn của mã, được gọi là Cây cú pháp trừu tượng [AST]

AST được tạo nội tuyến với quy trình thông dịch CPython, nhưng bạn cũng có thể tạo chúng bằng cả Python bằng cách sử dụng mô-đun

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
924 trong Thư viện chuẩn cũng như thông qua API C

Trước khi đi sâu vào triển khai C của AST, sẽ rất hữu ích nếu bạn hiểu AST trông như thế nào đối với một đoạn mã Python đơn giản

Để làm điều này, đây là một ứng dụng đơn giản có tên là

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
189 cho hướng dẫn này. Nó hiển thị các hướng dẫn AST và mã byte [mà chúng tôi sẽ trình bày sau] trong giao diện người dùng web

Để cài đặt

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
189

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
50

Sau đó, mở REPL bằng cách chạy

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
57 tại dòng lệnh mà không có đối số

>>>

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
51

Bạn sẽ thấy thông báo trên dòng lệnh rằng máy chủ web đã khởi động trên cổng

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
928. Nếu bạn đang sử dụng cổng đó cho mục đích khác, bạn có thể thay đổi cổng đó bằng cách gọi số
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
929 hoặc một số cổng khác

Trong trình duyệt web, bạn có thể xem phân tích chi tiết về chức năng của mình

Biểu đồ dưới cùng bên trái là hàm bạn đã khai báo trong REPL, được biểu diễn dưới dạng Cây cú pháp trừu tượng. Mỗi nút trong cây là một loại AST. Chúng được tìm thấy trong mô-đun

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
924 và tất cả đều kế thừa từ
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
931

Một số nút có các thuộc tính liên kết chúng với các nút con, không giống như CST, có thuộc tính nút con chung

Ví dụ: nếu bạn nhấp vào nút Chỉ định ở giữa, nút này sẽ liên kết đến dòng

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
932

Nó có hai thuộc tính

  1. cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    933 là một danh sách các tên để chỉ định. Nó là một danh sách bởi vì bạn có thể gán cho nhiều biến với một biểu thức duy nhất bằng cách giải nén
  2. cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    934 là giá trị cần gán, trong trường hợp này là câu lệnh
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    935,
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    921

Nếu bạn nhấp vào câu lệnh

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
935, nó sẽ hiển thị các thuộc tính liên quan

  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    938. nút bên trái của toán tử
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    939. toán tử, trong trường hợp này, một nút
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    940 [
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    131] để bổ sung
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    942. nút bên phải của toán tử

Biên dịch AST trong C không phải là một nhiệm vụ đơn giản, vì vậy mô-đun

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
913 có hơn 5000 dòng mã

Có một vài điểm vào, tạo thành một phần của API công khai của AST. Trong phần cuối cùng về từ vựng và trình phân tích cú pháp, bạn đã dừng khi gọi tới. Đến giai đoạn này, trình thông dịch Python đã tạo ra một CST ở định dạng cây

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
945

Sau đó nhảy vào bên trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
913, bạn có thể thấy nó nhận được cây
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
945, tên tệp, cờ trình biên dịch và
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
190

Kiểu trả về từ hàm này là , được định nghĩa trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
951.
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
950 là cấu trúc vùng chứa cho một trong 5 loại mô-đun trong Python

  1. cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    953
  2. cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    954
  3. cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    955
  4. cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    956
  5. cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    957

Trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
951, bạn có thể thấy rằng loại
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
955 yêu cầu trường
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
960, đây là loại
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
961. Loại
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
961 cũng được định nghĩa trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
951

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
52

Các loại AST đều được liệt kê trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
964. Bạn sẽ thấy các loại mô-đun, loại câu lệnh, loại biểu thức, toán tử và khả năng hiểu đều được liệt kê. Tên của các loại trong tài liệu này liên quan đến các lớp do AST tạo ra và các lớp tương tự có tên trong thư viện mô-đun chuẩn
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
924

Các tham số và tên trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
951 tương quan trực tiếp với các tham số được chỉ định trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
964

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
53

Tệp tiêu đề C và các cấu trúc ở đó để chương trình

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
913 có thể nhanh chóng tạo các cấu trúc có con trỏ tới dữ liệu liên quan

Nhìn vào bạn có thể thấy rằng nó thực chất là một tuyên bố

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
970 xung quanh kết quả từ
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
971.
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
972 là một trong những chức năng cốt lõi được AST sử dụng để xác định loại nút trong cây cú pháp cụ thể là gì. Trong trường hợp nó chỉ nhìn vào nút đầu tiên, vì vậy nó chỉ có thể là một trong các loại mô-đun được xác định là
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
953,
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
954,
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
955,
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
956

Kết quả của

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
972 sẽ là một biểu tượng hoặc loại mã thông báo mà chúng ta đã rất quen thuộc ở giai đoạn này

Đối với

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
979, kết quả phải là một
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
953. Các mô-đun là một loạt các câu lệnh, trong đó có một số loại. Logic để duyệt qua các phần tử con của
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
981 và tạo các nút câu lệnh nằm trong. Hàm này được gọi một lần nếu chỉ có 1 câu lệnh trong mô-đun hoặc vòng lặp nếu có nhiều câu lệnh. Kết quả
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
953 sau đó được trả về với
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
190

Đối với

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
985, kết quả phải là một
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
955. Kết quả từ
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
987, là phần tử con đầu tiên của
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
981 được truyền vào để trả về loại
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
961.
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
961 này được gửi đến
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
992 bằng PyArena để tạo một nút biểu thức, sau đó được trả lại như một kết quả

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
54

Bên trong hàm, có một câu lệnh

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
970 khác cho từng loại câu lệnh có thể [
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
995,
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
996, v.v.] và mã để xác định các đối số cho lớp nút

Một trong những hàm đơn giản hơn là đối với biểu thức lũy thừa, i. e. ,

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
997 là 2 mũ 4. Hàm này bắt đầu bằng cách lấy , là số
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
999 trong ví dụ của chúng ta, sau đó nếu nó có một con, nó sẽ trả về biểu thức nguyên tử. Nếu nó có nhiều hơn một con, nó sẽ lấy bên tay phải [số
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
500] và trả về một
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
935 [phép toán nhị phân] với toán tử là
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
502 [lũy thừa], bên trái của
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
503 [2] và bên phải

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
55

Bạn có thể thấy kết quả của việc này nếu bạn gửi một hàm ngắn tới mô-đun

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
189

>>>

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
56

Trong giao diện người dùng, bạn cũng có thể thấy các thuộc tính tương ứng

Tóm lại, mỗi loại câu lệnh và biểu thức đều có một hàm

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
506 tương ứng để tạo ra nó. Các đối số được xác định trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
964 và được hiển thị thông qua mô-đun
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
924 trong thư viện chuẩn. Nếu một biểu thức hoặc câu lệnh có con, thì nó sẽ gọi hàm con
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
509 tương ứng trong một lần duyệt theo chiều sâu

Loại bỏ các quảng cáo

Phần kết luận

Tính linh hoạt và API thực thi cấp thấp của CPython khiến nó trở thành ứng cử viên lý tưởng cho một công cụ viết kịch bản nhúng. Bạn sẽ thấy CPython được sử dụng trong nhiều ứng dụng giao diện người dùng, chẳng hạn như Thiết kế trò chơi, đồ họa 3D và tự động hóa hệ thống

Quá trình thông dịch linh hoạt và hiệu quả, và bây giờ bạn đã hiểu về cách thức hoạt động của nó, bạn đã sẵn sàng để hiểu trình biên dịch

Phần 3. Trình biên dịch và vòng lặp thực thi CPython

Trong Phần 2, bạn đã thấy cách trình thông dịch CPython nhận đầu vào, chẳng hạn như tệp hoặc chuỗi và chuyển đổi nó thành Cây cú pháp trừu tượng hợp lý. Chúng tôi vẫn chưa ở giai đoạn mã này có thể được thực thi. Tiếp theo, chúng ta phải đi sâu hơn để chuyển đổi Cây cú pháp trừu tượng thành một tập hợp các lệnh tuần tự mà CPU có thể hiểu được

Biên soạn

Bây giờ trình thông dịch có một AST với các thuộc tính cần thiết cho từng thao tác, hàm, lớp và không gian tên. Công việc của trình biên dịch là biến AST thành thứ mà CPU có thể hiểu được

Nhiệm vụ biên dịch này được chia thành 2 phần

  1. Duyệt qua cây và tạo biểu đồ luồng điều khiển, biểu thị trình tự logic để thực hiện
  2. Chuyển đổi các nút trong CFG thành các câu lệnh nhỏ hơn, có thể thực thi được, được gọi là mã byte

Trước đó, chúng ta đã xem cách các tệp được thực thi và hàm

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
648 trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
600. Bên trong chức năng này, chúng tôi đã chuyển đổi điều khiển
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
512 thành một
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
604, loại
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
950. Nhiệm vụ này đã được hoàn thành bởi , lần lượt gọi
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
516,
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
517 và sau đó là AST

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
57

Mô-đun kết quả từ cuộc gọi đến được gửi đến vẫn trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
600. Đây là một chức năng nhỏ nhận từ và gửi nó đến. Bạn sẽ giải quyết trong phần tiếp theo

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
58

Hàm này là điểm vào chính của trình biên dịch CPython. Nó lấy một mô-đun Python làm đối số chính, cùng với tên của tệp, toàn cầu, cục bộ và

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
190, tất cả được tạo trước đó trong quy trình thông dịch

Bây giờ chúng ta đang bắt đầu tìm hiểu sâu về trình biên dịch CPython, với hàng thập kỷ phát triển và lý thuyết Khoa học Máy tính đằng sau nó. Đừng để bị trì hoãn bởi ngôn ngữ. Khi chúng tôi chia nhỏ trình biên dịch thành các bước hợp lý, nó sẽ có ý nghĩa

Trước khi trình biên dịch bắt đầu, một trạng thái trình biên dịch chung được tạo. Loại này,

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
526 được định nghĩa trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
527 và chứa các thuộc tính được trình biên dịch sử dụng để ghi nhớ các cờ trình biên dịch, ngăn xếp và
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
190

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
59

Bên trong, có 11 bước chính xảy ra

  1. Tạo một thuộc tính
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    530 trống cho mô-đun nếu nó không tồn tại
  2. Tạo một thuộc tính
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    531 trống cho mô-đun nếu nó không tồn tại
  3. Đặt tên tệp của trạng thái trình biên dịch chung thành đối số tên tệp
  4. Đặt trường cấp phát bộ nhớ cho trình biên dịch thành trường được trình thông dịch sử dụng
  5. Sao chép bất kỳ cờ
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    532 nào trong mô-đun sang các cờ tương lai trong trình biên dịch
  6. Hợp nhất các cờ thời gian chạy được cung cấp bởi dòng lệnh hoặc biến môi trường
  7. Kích hoạt bất kỳ tính năng
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    532 nào trong trình biên dịch
  8. Đặt mức tối ưu hóa thành đối số được cung cấp hoặc mặc định
  9. Xây dựng bảng ký hiệu từ đối tượng mô-đun
  10. Chạy trình biên dịch với trạng thái trình biên dịch và trả về đối tượng mã
  11. Giải phóng mọi bộ nhớ được cấp phát bởi trình biên dịch

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
60

Cờ tương lai và cờ biên dịch

Trước khi trình biên dịch chạy, có hai loại cờ để chuyển đổi các tính năng bên trong trình biên dịch. Chúng đến từ hai nơi

  1. Trạng thái trình thông dịch, có thể là các tùy chọn dòng lệnh, được đặt trong
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    374 hoặc thông qua các biến môi trường
  2. Việc sử dụng các câu lệnh
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    532 bên trong mã nguồn thực tế của mô-đun

Để phân biệt hai loại cờ, hãy nghĩ rằng cờ

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
532 là bắt buộc do cú pháp hoặc tính năng trong mô-đun cụ thể đó. Ví dụ: Python3. 7 đã giới thiệu đánh giá chậm các gợi ý loại thông qua cờ tương lai
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
537

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
61

Mã sau câu lệnh này có thể sử dụng các gợi ý loại chưa được giải quyết, do đó, câu lệnh

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
532 là bắt buộc. Nếu không, mô-đun sẽ không nhập. Sẽ không thể duy trì được nếu yêu cầu người nhập mô-đun bật cờ trình biên dịch cụ thể này theo cách thủ công

Các cờ trình biên dịch khác dành riêng cho môi trường, vì vậy chúng có thể thay đổi cách mã thực thi hoặc cách trình biên dịch chạy, nhưng chúng không nên liên kết với nguồn giống như cách mà các câu lệnh

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
532 thực hiện

Một ví dụ về cờ trình biên dịch sẽ là. Cờ này vô hiệu hóa bất kỳ câu lệnh

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
58 nào, có thể đã được đưa vào mã cho mục đích gỡ lỗi. Nó cũng có thể được kích hoạt với cài đặt biến môi trường
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
543

Bảng biểu tượng

Trong đó có một tham chiếu đến một

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
545 và một lệnh gọi với mô-đun sẽ được thực thi

Mục đích của bảng ký hiệu là cung cấp danh sách các không gian tên, toàn cầu và cục bộ để trình biên dịch sử dụng để tham chiếu và giải quyết các phạm vi

Cấu trúc

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
545 trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
548 được ghi lại rõ ràng, vì vậy rõ ràng từng trường dùng để làm gì. Cần có một phiên bản có thể ký hiệu cho trình biên dịch, do đó, không gian tên trở nên cần thiết

Nếu bạn tạo một hàm có tên là

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
549 trong một mô-đun và khai báo một hàm khác có cùng tên trong một mô-đun khác, bạn muốn chắc chắn rằng hàm nào được gọi. Bảng ký hiệu phục vụ mục đích này, cũng như đảm bảo rằng các biến được khai báo trong phạm vi hẹp không tự động trở thành biến toàn cầu [xét cho cùng, đây không phải là JavaScript]

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
62

Một số API bảng biểu tượng được hiển thị thông qua mô-đun

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
545 trong thư viện tiêu chuẩn. Bạn có thể cung cấp một biểu thức hoặc một mô-đun và nhận một phiên bản
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
551

Bạn có thể cung cấp một chuỗi có biểu thức Python và

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
552 của
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
553 hoặc một mô-đun, hàm hoặc lớp và
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
554 của
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
555 để lấy bảng ký hiệu

Lặp lại các phần tử trong bảng, chúng ta có thể thấy một số trường công khai và riêng tư và các loại của chúng

>>>

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
63

Mã C đằng sau tất cả nằm trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
556 và giao diện chính là chức năng

Tương tự như hàm AST cấp cao nhất mà chúng tôi đã đề cập trước đó, hàm chuyển đổi giữa các loại có thể có của

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
950 [Mô-đun, Biểu thức, Tương tác, Bộ, Loại chức năng] và truy cập từng câu lệnh bên trong chúng

Hãy nhớ rằng,

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
950 là một phiên bản AST, do đó, bây giờ sẽ khám phá đệ quy các nút và nhánh của cây và thêm các mục vào symtable

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
64

Vì vậy, đối với một mô-đun, sẽ lặp qua từng câu lệnh trong mô-đun và gọi. Đây là một câu lệnh

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
970 khổng lồ với một trường hợp cho từng loại câu lệnh [được định nghĩa trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
964]

Đối với mỗi loại câu lệnh, có logic cụ thể cho loại câu lệnh đó. Ví dụ, một định nghĩa hàm có logic cụ thể cho

  1. Nếu độ sâu đệ quy vượt quá giới hạn, hãy tăng lỗi độ sâu đệ quy
  2. Tên của hàm sẽ được thêm làm biến cục bộ
  3. Các giá trị mặc định cho các đối số tuần tự sẽ được giải quyết
  4. Các giá trị mặc định cho các đối số từ khóa sẽ được giải quyết
  5. Mọi chú thích cho các đối số hoặc kiểu trả về đều được giải quyết
  6. Bất kỳ chức năng trang trí được giải quyết
  7. Khối mã với nội dung của chức năng được truy cập trong
  8. Các đối số được truy cập
  9. Phần thân của hàm được thăm

Ghi chú. Nếu bạn đã từng thắc mắc tại sao các đối số mặc định của Python lại có thể thay đổi, thì lý do nằm ở hàm này. Bạn có thể thấy chúng là một con trỏ tới biến trong symtable. Không có công việc bổ sung nào được thực hiện để sao chép bất kỳ giá trị nào sang loại không thay đổi

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
65

Khi symtable kết quả đã được tạo, nó sẽ được gửi lại để sử dụng cho trình biên dịch

Quy trình biên dịch cốt lõi

Bây giờ đã có trạng thái trình biên dịch, một symtable và một mô-đun ở dạng AST, quá trình biên dịch thực sự có thể bắt đầu

Mục đích của trình biên dịch cốt lõi là để

  • Chuyển đổi trạng thái, symtable và AST thành Control-Flow-Graph [CFG]
  • Bảo vệ giai đoạn thực thi khỏi các ngoại lệ trong thời gian chạy bằng cách bắt bất kỳ lỗi logic và mã nào và nêu chúng tại đây

Bạn có thể gọi trình biên dịch CPython bằng mã Python bằng cách gọi hàm tích hợp sẵn

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
568. Nó trả về một phiên bản
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
569

>>>

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
66

Tương tự với hàm

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
570, một biểu thức đơn giản phải có chế độ là
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
571 và một mô-đun, hàm hoặc lớp phải có chế độ là
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
572

Mã được biên dịch có thể được tìm thấy trong thuộc tính

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
573 của đối tượng mã

>>>

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
67

Ngoài ra còn có một mô-đun

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
574 trong thư viện tiêu chuẩn, phân tách các hướng dẫn mã byte và có thể in chúng trên màn hình hoặc cung cấp cho bạn danh sách các phiên bản
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
575

Nếu bạn nhập

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
574 và cung cấp cho hàm
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
577 thuộc tính
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
573 của đối tượng mã, nó sẽ phân tách hàm đó và in hướng dẫn trên REPL

>>>

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
68

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
579,
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
580,
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
581 và
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
582 đều là các lệnh mã byte. Chúng được gọi là mã byte vì ở dạng nhị phân, chúng dài một byte. Tuy nhiên, kể từ Python 3. 6, định dạng lưu trữ đã được thay đổi thành
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
583, vì vậy bây giờ về mặt kỹ thuật, chúng là mã từ, không phải mã byte

Có sẵn cho mỗi phiên bản Python và nó thay đổi giữa các phiên bản. Ví dụ, trong Python 3. 7, một số hướng dẫn mã byte mới đã được giới thiệu để tăng tốc độ thực hiện các lệnh gọi phương thức cụ thể

Trong phần trước, chúng ta đã khám phá gói

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
189. Điều này bao gồm trực quan hóa loại đối tượng mã bằng cách chạy trình biên dịch. Nó cũng hiển thị các hoạt động Bytecode bên trong các đối tượng mã

Thực thi lại instaviz để xem đối tượng mã và mã byte cho hàm được xác định trên REPL

>>>

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
69

Nếu bây giờ chúng ta chuyển sang , một chức năng được sử dụng để chuyển sang các chức năng biên dịch khác nhau tùy thuộc vào loại mô-đun. Chúng tôi sẽ cho rằng

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
604 là một
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
953. Mô-đun được biên dịch sang trạng thái trình biên dịch và sau đó được chạy để tạo một

Đối tượng mã mới được trả lại và gửi đi để thực thi

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
80

Hàm này có một số cờ tối ưu hóa, sau đó lặp lại từng câu lệnh trong mô-đun và truy cập nó, tương tự như cách hoạt động của hàm

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
545

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
81

Loại câu lệnh được xác định thông qua lệnh gọi hàm, xem xét loại của nút AST

Thông qua một số macro thông minh,

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
594 gọi một hàm trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
527 cho từng loại câu lệnh

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
82

Đối với một

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
596 [thể loại cho một câu lệnh], trình biên dịch sau đó sẽ thả vào và chuyển qua tất cả các loại câu lệnh tiềm năng được tìm thấy trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
964

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
83

Ví dụ, hãy tập trung vào câu lệnh

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
599, trong Python là

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
84

Nếu câu lệnh là loại

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
599, nó sẽ gọi. Có một hàm
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
602 tương đương cho tất cả các loại câu lệnh và biểu thức. Các loại đơn giản hơn tạo các hướng dẫn mã byte nội tuyến, một số loại câu lệnh phức tạp hơn gọi các hàm khác

Nhiều câu lệnh có thể có câu lệnh phụ. Vòng lặp

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
603 có phần thân, nhưng bạn cũng có thể có các biểu thức phức tạp trong phép gán và trình vòng lặp

Các câu lệnh

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
604 của trình biên dịch sẽ gửi các khối đến trạng thái của trình biên dịch. Các khối này chứa các lệnh, cấu trúc dữ liệu lệnh trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
527 có mã lệnh, bất kỳ đối số nào và khối đích [nếu đây là lệnh nhảy], nó cũng chứa số dòng

Đối với câu lệnh nhảy, chúng có thể là câu lệnh nhảy tuyệt đối hoặc tương đối. Câu lệnh nhảy được sử dụng để “nhảy” từ thao tác này sang thao tác khác. Các câu lệnh nhảy tuyệt đối chỉ định số thao tác chính xác trong đối tượng mã được biên dịch, trong khi các câu lệnh nhảy tương đối chỉ định mục tiêu nhảy liên quan đến thao tác khác

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
85

Vì vậy, một khối khung [loại

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
606], chứa các trường sau

  • Một con trỏ
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    607, liên kết đến danh sách các khối cho trạng thái trình biên dịch
  • Một danh sách các hướng dẫn
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    608, với cả kích thước danh sách được phân bổ
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    609 và số được sử dụng
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    610
  • Khối tiếp theo sau khối này
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    611
  • Liệu khối có được “nhìn thấy” bởi trình biên dịch khi duyệt theo chiều sâu trước hay không
  • Nếu khối này có opcode
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    582 [
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    613]
  • Độ sâu của ngăn xếp khi khối này được nhập vào [______4614]
  • Phần bù hướng dẫn cho trình biên dịch hợp ngữ

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
86

Câu lệnh

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
599 ở đâu đó ở giữa về độ phức tạp. Có 15 bước trong quá trình biên dịch câu lệnh
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
599 với cú pháp
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
617

  1. Tạo một khối mã mới có tên là
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    618, khối này cấp phát bộ nhớ và tạo một con trỏ
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    606
  2. Tạo một khối mã mới có tên là
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    620
  3. Tạo một khối mã mới có tên là
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    621
  4. Đẩy một khối khung loại
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    622 vào ngăn xếp với khối đầu vào là khối
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    618 và khối khối đầu ra là
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    621
  5. Truy cập biểu thức trình vòng lặp, biểu thức này sẽ thêm bất kỳ thao tác nào cho trình vòng lặp
  6. Thêm hoạt động
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    625 vào trạng thái trình biên dịch
  7. Chuyển sang khối
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    618
  8. Gọi
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    627 gọi để thêm hoạt động
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    629 với đối số của khối
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    620
  9. Truy cập vào
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    631 và thêm bất kỳ mã đặc biệt nào, chẳng hạn như giải nén bộ dữ liệu, vào khối
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    618
  10. Truy cập từng câu lệnh trong phần thân của vòng lặp for
  11. Gọi
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    633 gọi để thêm hoạt động
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    635 cho biết sau khi phần thân được thực thi, nhảy trở lại điểm bắt đầu của vòng lặp
  12. Di chuyển đến khối
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    620
  13. Đưa khối khung
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    622 ra khỏi ngăn xếp
  14. Truy cập các câu lệnh bên trong phần
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    638 của vòng lặp for
  15. Sử dụng khối
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    621

Nhắc lại cấu trúc

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
606. Bạn có thể thấy trong quá trình biên dịch câu lệnh for, các khối khác nhau được tạo và đẩy vào ngăn xếp và khối khung của trình biên dịch như thế nào

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
87

Tùy thuộc vào loại hoạt động, có các đối số khác nhau được yêu cầu. Ví dụ: chúng tôi đã sử dụng

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
633 và
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
627 ở đây, đề cập đến “THÊM Thao tác với Nhảy đến một vị trí TƯƠNG QUAN” và “THÊM Thao tác với Nhảy đến một vị trí TUYỆT ĐỐI”. Điều này đề cập đến các macro
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
643 và
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
633 gọi
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
645 và đặt đối số
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
646 thành 0 và 1 tương ứng

Có một số macro khác, chẳng hạn như lệnh gọi

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
647 thêm một thao tác với đối số số nguyên hoặc lệnh gọi
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
649 thêm thao tác với đối số
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
301

Khi các giai đoạn này đã hoàn thành, trình biên dịch có một danh sách các khối khung, mỗi khối chứa một danh sách các hướng dẫn và một con trỏ tới khối tiếp theo

Hội đồng

Với trạng thái trình biên dịch, trình hợp dịch thực hiện “tìm kiếm theo chiều sâu” của các khối và hợp nhất các hướng dẫn thành một chuỗi mã byte đơn. Trạng thái trình biên dịch chương trình được khai báo trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
527

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
88

Hàm

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
588 có một số nhiệm vụ

  • Tính số khối để cấp phát bộ nhớ
  • Đảm bảo rằng mọi khối rơi ra khỏi cuối đều trả về
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    654, đây là lý do tại sao mọi hàm trả về
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    654, cho dù có tồn tại câu lệnh
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    656 hay không
  • Giải quyết bất kỳ phần bù nào của câu lệnh nhảy được đánh dấu là tương đối
  • Gọi
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    657 để thực hiện tìm kiếm chuyên sâu các khối
  • Phát ra tất cả các hướng dẫn cho trình biên dịch
  • Gọi với trạng thái trình biên dịch để tạo
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    520

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
89

Tìm kiếm theo chiều sâu được thực hiện bởi hàm trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
527, theo sau các con trỏ
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
611 trong mỗi khối, đánh dấu chúng là đã nhìn thấy bằng cách chuyển đổi
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
663 và sau đó thêm chúng vào danh sách trình biên dịch mã
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
664 theo thứ tự ngược lại

Hàm lặp lại danh sách thứ tự sau của trình biên dịch hợp ngữ và đối với mỗi khối, nếu nó có thao tác nhảy, hãy gọi đệ quy cho bước nhảy đó

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
90

Tạo đối tượng mã

Nhiệm vụ của là đi qua trạng thái trình biên dịch, một số thuộc tính của trình biên dịch chương trình hợp ngữ và đưa chúng vào một

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
520 bằng cách gọi

Tên biến, hằng được đặt làm thuộc tính cho đối tượng mã

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
91

Bạn cũng có thể nhận thấy rằng mã byte được gửi tới trước khi nó được gửi tới. Chức năng này là một phần của quá trình tối ưu hóa bytecode trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
671

Trình tối ưu hóa lỗ nhìn trộm xem qua các hướng dẫn mã byte và trong một số trường hợp nhất định, hãy thay thế chúng bằng các hướng dẫn khác. Ví dụ: có một trình tối ưu hóa được gọi là "mở ra liên tục", vì vậy nếu bạn đặt câu lệnh sau vào tập lệnh của mình

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
92

Nó tối ưu hóa điều đó để

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
93

Vì 1 và 5 là các giá trị không đổi nên kết quả phải luôn giống nhau

Phần kết luận

Chúng ta có thể kết hợp tất cả các giai đoạn này với mô-đun instaviz

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
94

Sẽ tạo ra một biểu đồ AST

Với các hướng dẫn mã byte theo trình tự

Ngoài ra, đối tượng mã có tên biến, hằng số và mã nhị phân

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
573

Loại bỏ các quảng cáo

Chấp hành

Vào năm 1600, chúng tôi đã chia tay ngay trước cuộc gọi tới

Cuộc gọi này nhận một đối tượng mã, được tìm nạp từ tệp

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
121 đã sắp xếp theo thứ tự hoặc được biên dịch qua các giai đoạn AST và trình biên dịch

sẽ chuyển toàn cầu, địa phương,

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
190 và biên dịch
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
520 sang trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
682

Giai đoạn này hình thành thành phần thực thi của CPython. Mỗi hoạt động mã byte được thực hiện và thực thi bằng cách sử dụng hệ thống dựa trên “Khung ngăn xếp”

Khung ngăn xếp là gì?

Khung ngăn xếp là một loại dữ liệu được sử dụng bởi nhiều thời gian chạy, không chỉ Python, cho phép các hàm được gọi và các biến được trả về giữa các hàm. Khung ngăn xếp cũng chứa các đối số, biến cục bộ và thông tin trạng thái khác

Thông thường, một Khung ngăn xếp tồn tại cho mọi lệnh gọi hàm và chúng được xếp chồng lên nhau theo thứ tự. Bạn có thể thấy ngăn xếp khung của CPython bất cứ khi nào một ngoại lệ không được xử lý và ngăn xếp được in trên màn hình

là API công khai để đánh giá một đối tượng mã. Logic để đánh giá được phân chia giữa và , cả hai đều nằm trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
324

API công khai sẽ xây dựng khung thực thi từ đỉnh ngăn xếp bằng cách gọi

Việc xây dựng khung thực thi đầu tiên có nhiều bước

  1. Đối số từ khóa và vị trí được giải quyết
  2. Việc sử dụng
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    687 và
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    688 trong định nghĩa hàm đã được giải quyết
  3. Các đối số được thêm dưới dạng biến cục bộ vào phạm vi
  4. Các đồng quy trình và Trình tạo được tạo, bao gồm cả Trình tạo không đồng bộ

Đối tượng khung trông như thế này

Hãy bước qua các trình tự đó

1. Xây dựng trạng thái chủ đề

Trước khi một khung có thể được thực thi, nó cần được tham chiếu từ một luồng. CPython có thể có nhiều luồng chạy cùng một lúc trong một trình thông dịch. Trạng thái Trình thông dịch bao gồm danh sách các luồng đó dưới dạng danh sách được liên kết. Cấu trúc luồng được gọi là và có nhiều tài liệu tham khảo xuyên suốt

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
324

Đây là cấu trúc của đối tượng trạng thái luồng

2. xây dựng khung

Đầu vào cho và do đó có các đối số cho

  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    693. một
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    520
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    695. một
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    696 với tên biến là khóa và giá trị của chúng
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    697. một
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    696 với tên biến là khóa và giá trị của chúng

Các đối số khác là tùy chọn và không được sử dụng cho API cơ bản

  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    699. một
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    800 với các giá trị đối số vị trí theo thứ tự và
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    801 cho số lượng giá trị
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    802. một danh sách các tên đối số từ khóa
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    803. một danh sách các giá trị đối số từ khóa và
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    804 cho số lượng chúng
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    805. một danh sách các giá trị mặc định cho các đối số vị trí và
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    806 cho độ dài
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    807. một từ điển với các giá trị mặc định cho các đối số từ khóa
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    808. một bộ có chuỗi để hợp nhất vào trường đối tượng mã
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    809
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    810. tên cho câu lệnh đánh giá này dưới dạng một chuỗi
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    811. tên đủ điều kiện cho tuyên bố đánh giá này dưới dạng một chuỗi

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
95

3. Chuyển đổi tham số từ khóa thành từ điển

Nếu định nghĩa hàm chứa một kiểu bắt tất cả kiểu

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
688 cho các đối số từ khóa, thì một từ điển mới sẽ được tạo và các giá trị được sao chép qua. Sau đó, tên
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
803 được đặt làm biến, như trong ví dụ này

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
96

Logic để tạo từ điển đối số từ khóa nằm trong phần tiếp theo của

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
97

Biến

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
814 sẽ tham chiếu đến một
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
815 nếu tìm thấy bất kỳ đối số từ khóa nào

4. Chuyển đổi các đối số vị trí thành các biến

Tiếp theo, mỗi đối số vị trí [nếu được cung cấp] được đặt làm biến cục bộ

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
98

Ở cuối vòng lặp, bạn sẽ thấy một lệnh gọi đến có giá trị, vì vậy nếu một đối số vị trí được xác định bằng một giá trị, thì giá trị đó khả dụng trong phạm vi này

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
99

Ngoài ra, bộ đếm tham chiếu cho các biến đó được tăng lên, vì vậy trình thu gom rác sẽ không xóa chúng cho đến khi khung được đánh giá

5. Đóng gói các đối số vị trí vào
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
687

Tương tự như

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
688, một đối số chức năng được thêm vào trước một
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
130 có thể được đặt để bắt tất cả các đối số vị trí còn lại. Đối số này là một bộ và tên
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
687 được đặt làm biến cục bộ

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
00

6. Đang tải đối số từ khóa

Nếu hàm được gọi với các đối số và giá trị từ khóa, thì từ điển

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
814 được tạo ở bước 4 hiện chứa đầy bất kỳ đối số từ khóa nào còn lại do người gọi chuyển không phân giải thành đối số được đặt tên hoặc đối số vị trí

Ví dụ: đối số

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
503 không phải là vị trí hoặc được đặt tên, vì vậy nó được thêm vào
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
823

>>>

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
01

Đối số chỉ theo vị trí là một tính năng mới trong Python 3. 8. Được giới thiệu trong PEP570, đối số chỉ vị trí là cách ngăn người dùng API của bạn sử dụng đối số vị trí bằng cú pháp từ khóa

Ví dụ: chức năng đơn giản này chuyển đổi Farenheit thành Celcius. Lưu ý, việc sử dụng

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
824 làm đối số đặc biệt sẽ tách biệt các đối số chỉ vị trí với các đối số khác

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
02

Tất cả các đối số ở bên trái của

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
824 chỉ được gọi là đối số vị trí và các đối số ở bên phải có thể được gọi là đối số vị trí hoặc từ khóa

>>>

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
03

Gọi hàm bằng cách sử dụng đối số từ khóa thành đối số chỉ vị trí sẽ tăng

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
826

>>>

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
04

Độ phân giải của các giá trị từ điển đối số từ khóa xuất hiện sau khi giải nén tất cả các đối số khác. Các đối số chỉ vị trí PEP570 được hiển thị bằng cách bắt đầu vòng lặp đối số từ khóa tại

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
827. Nếu ký hiệu
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
824 được sử dụng trên đối số thứ 3, giá trị của
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
827 sẽ là
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
999.
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
831 được gọi cho mỗi đối số còn lại để thêm nó vào từ điển
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
697, vì vậy khi thực thi, mỗi đối số từ khóa là các biến cục bộ có phạm vi

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
05

Ở cuối vòng lặp, bạn sẽ thấy một cuộc gọi đến với giá trị. Nếu một đối số từ khóa được xác định bằng một giá trị, thì giá trị đó khả dụng trong phạm vi này

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
06

7. Thêm các đối số vị trí bị thiếu

Bất kỳ đối số vị trí nào được cung cấp cho lệnh gọi hàm không có trong danh sách đối số vị trí sẽ được thêm vào bộ dữ liệu

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
687 nếu bộ dữ liệu này không tồn tại, sẽ xảy ra lỗi

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
07

8. Thêm đối số từ khóa bị thiếu

Bất kỳ đối số từ khóa nào được cung cấp cho lệnh gọi hàm không có trong danh sách đối số từ khóa được đặt tên sẽ được thêm vào từ điển

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
688 nếu từ điển này không tồn tại, sẽ xảy ra lỗi

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
08

9. Thu gọn đóng cửa

Bất kỳ tên bao đóng nào cũng được thêm vào danh sách tên biến tự do của đối tượng mã

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
09

10. Tạo Trình tạo, Coroutines và Trình tạo không đồng bộ

Nếu đối tượng mã được đánh giá có cờ là trình tạo, trình tạo coroutine hoặc trình tạo không đồng bộ, thì một khung mới được tạo bằng một trong các phương thức duy nhất trong thư viện Trình tạo, Coroutine hoặc Async và khung hiện tại được thêm làm thuộc tính

Khung mới sau đó được trả lại và khung ban đầu không được đánh giá. Khung chỉ được đánh giá khi phương thức trình tạo/coroutine/async được gọi để thực thi mục tiêu của nó

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
10

Cuối cùng, được gọi với khung mới

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
11

Thi hành khung

Như đã đề cập trước đó trong các chương trình biên dịch và AST, đối tượng mã chứa mã hóa nhị phân của mã byte sẽ được thực thi. Nó cũng chứa một danh sách các biến và một bảng ký hiệu

Các biến cục bộ và toàn cục được xác định trong thời gian chạy dựa trên cách hàm, mô-đun hoặc khối đó được gọi. Thông tin này được thêm vào khung bởi chức năng. Có những cách sử dụng khung khác, chẳng hạn như trình trang trí coroutine, tự động tạo một khung với mục tiêu là một biến

API công khai, gọi chức năng đánh giá khung được định cấu hình của trình thông dịch trong thuộc tính

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
839. Đánh giá khung có thể cắm được trong Python 3. 7 với PEP 523

là chức năng mặc định và thật bất thường khi sử dụng bất kỳ thứ gì khác ngoài chức năng này

Các khung được thực thi trong vòng lặp thực thi chính bên trong. Chức năng này là chức năng trung tâm kết hợp mọi thứ lại với nhau và đưa mã của bạn vào cuộc sống. Nó chứa nhiều thập kỷ tối ưu hóa vì ngay cả một dòng mã cũng có thể có tác động đáng kể đến hiệu suất của toàn bộ CPython

Mọi thứ được thực thi trong CPython đều đi qua chức năng này

Ghi chú. Một điều bạn có thể nhận thấy khi đọc

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
324, là số lần các macro C đã được sử dụng. C Macro là một cách để có mã tuân thủ KHÔ mà không cần thực hiện các lệnh gọi hàm. Trình biên dịch chuyển đổi macro thành mã C và sau đó biên dịch mã được tạo

Nếu bạn muốn xem mã mở rộng, bạn có thể chạy

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
843 trên Linux và macOS

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
12

Ngoài ra, Visual Studio Code có thể thực hiện mở rộng macro nội tuyến sau khi bạn đã cài đặt tiện ích mở rộng C/C++ chính thức

Chúng ta có thể từng bước thực thi khung trong Python 3. 7 trở lên bằng cách bật thuộc tính theo dõi trên chuỗi hiện tại

Ví dụ mã này đặt chức năng theo dõi toàn cầu thành một chức năng có tên là

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
844 lấy ngăn xếp từ khung hiện tại, in các mã lệnh đã được phân tách ra màn hình và một số thông tin bổ sung để gỡ lỗi

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
13

Điều này in mã trong mỗi ngăn xếp và trỏ đến thao tác tiếp theo trước khi nó được thực thi. Khi một khung trả về một giá trị, câu lệnh trả về được in

Danh sách đầy đủ các hướng dẫn có sẵn trên tài liệu

ngăn xếp giá trị

Bên trong vòng đánh giá cốt lõi, một ngăn xếp giá trị được tạo. Ngăn xếp này là danh sách các con trỏ tới các phiên bản

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
301 tuần tự

Một cách để nghĩ về ngăn xếp giá trị giống như một cái chốt gỗ mà bạn có thể xếp các hình trụ lên đó. Bạn sẽ chỉ thêm hoặc xóa một mục tại một thời điểm. Điều này được thực hiện bằng cách sử dụng macro

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
847, trong đó
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
848 là một con trỏ tới một
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
301

Ví dụ: nếu bạn đã tạo một

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
850 với giá trị 10 và đẩy nó vào ngăn xếp giá trị

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
14

Hành động này sẽ có tác dụng sau

Trong hoạt động tiếp theo, để tìm nạp giá trị đó, bạn sẽ sử dụng macro

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
851 để lấy giá trị cao nhất từ ​​ngăn xếp

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
15

Hành động này sẽ trả về giá trị cao nhất và kết thúc bằng một ngăn xếp giá trị trống

Nếu bạn thêm 2 giá trị vào ngăn xếp

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
16

Chúng sẽ kết thúc theo thứ tự mà chúng được thêm vào, vì vậy

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
848 sẽ được đẩy lên vị trí thứ hai trong ngăn xếp

Nếu bạn lấy giá trị cao nhất trong ngăn xếp, bạn sẽ nhận được một con trỏ tới

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
853 vì nó ở trên cùng

Nếu bạn cần tìm nạp con trỏ tới giá trị cao nhất trong ngăn xếp mà không cần bật nó lên, bạn có thể sử dụng thao tác

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
854, trong đó
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
855 là vị trí ngăn xếp

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
17

0 đại diện cho đỉnh của ngăn xếp, 1 sẽ là vị trí thứ hai

Để sao chép giá trị ở đầu ngăn xếp, có thể sử dụng macro

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
856 hoặc bằng cách sử dụng opcode
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
857

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
18

Hành động này sẽ sao chép giá trị ở trên cùng để tạo thành 2 con trỏ tới cùng một đối tượng

Có một macro xoay vòng

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
858 hoán đổi giá trị thứ nhất và thứ hai

Mỗi opcode đều có “hiệu ứng ngăn xếp” được xác định trước, được tính toán bởi hàm bên trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
527. Hàm này trả về delta theo số lượng giá trị bên trong ngăn xếp cho mỗi opcode

Ví dụ. Thêm một mục vào một danh sách

Trong Python, khi bạn tạo một danh sách, phương thức

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
305 có sẵn trên đối tượng danh sách

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
19

Trong đó

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
862 là một đối tượng, bạn muốn thêm vào cuối danh sách

Có 2 thao tác liên quan đến thao tác này.

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
863, để tải đối tượng
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
862 lên đầu ngăn xếp giá trị từ danh sách
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
697 trong khung và
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
866 để thêm đối tượng

Lần đầu tiên khám phá

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
863, có 5 bước

  1. Con trỏ tới

    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    862 được tải từ
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    869, trong đó biến cần tải là đối số hoạt động. Danh sách các con trỏ biến được lưu trữ trong ________ 4870, là bản sao của thuộc tính PyFrame ________ 4871. Đối số hoạt động là một số, trỏ đến chỉ mục trong con trỏ mảng
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    870. Điều này có nghĩa là việc tải cục bộ chỉ đơn giản là sao chép con trỏ thay vì phải tra cứu tên biến

  2. Nếu biến không còn tồn tại, lỗi biến cục bộ không liên kết sẽ xuất hiện

  3. Bộ đếm tham chiếu cho

    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    934 [trong trường hợp của chúng tôi là
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    862] được tăng thêm 1

  4. Con trỏ tới

    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    862 được đẩy lên đầu ngăn xếp giá trị

  5. Macro

    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    876 được gọi, nếu tính năng theo dõi được bật, vòng lặp sẽ lặp lại [với tất cả tính năng theo dõi], nếu tính năng theo dõi không được bật, một
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    877 được gọi tới
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    878, sẽ nhảy trở lại đầu vòng lặp cho lệnh tiếp theo

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
20

Bây giờ con trỏ tới

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
862 ở trên cùng của ngăn xếp giá trị. Lệnh tiếp theo
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
866 được chạy

Nhiều hoạt động mã byte đang tham chiếu đến các loại cơ sở, như PyUnicode, PyNumber. Ví dụ:

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
866 nối thêm một đối tượng vào cuối danh sách. Để đạt được điều này, nó bật con trỏ từ ngăn xếp giá trị và trả con trỏ về đối tượng cuối cùng trong ngăn xếp. Macro là lối tắt cho

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
21

Bây giờ con trỏ tới

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
862 được lưu dưới dạng
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
855. Con trỏ danh sách được tải từ
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
884

Sau đó, danh sách API C cho Python được gọi cho

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
885 và
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
855. Mã cho điều này nằm bên trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
887, mà chúng ta sẽ xem xét trong chương tiếp theo

Một cuộc gọi đến

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
888 được thực hiện, dự đoán rằng hoạt động tiếp theo sẽ là
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
635. Macro
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
888 có các câu lệnh
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
877 do trình biên dịch tạo cho mỗi câu lệnh
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
892 của hoạt động tiềm năng. Điều này có nghĩa là CPU có thể nhảy tới lệnh đó và không phải thực hiện lại vòng lặp

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
22

dự đoán opcode. Một số opcode có xu hướng đi theo cặp, do đó có thể dự đoán mã thứ hai khi mã thứ nhất được chạy. Ví dụ:

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
893 thường được theo sau bởi
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
894 hoặc
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
895

“Việc xác minh dự đoán tốn một bài kiểm tra tốc độ cao duy nhất của biến đăng ký so với hằng số. Nếu ghép nối tốt, thì dự đoán nhánh bên trong của chính bộ xử lý có khả năng thành công cao, dẫn đến quá trình chuyển đổi gần như bằng không sang opcode tiếp theo. Một dự đoán thành công sẽ lưu một chuyến đi qua eval-loop bao gồm cả nhánh trường hợp chuyển đổi không thể đoán trước của nó. Kết hợp với dự đoán nhánh bên trong của bộ xử lý, PREDICT thành công có tác dụng làm cho hai opcode chạy như thể chúng là một opcode mới với các phần thân được kết hợp. ”

Nếu thu thập số liệu thống kê opcode, bạn có hai lựa chọn

  1. Luôn bật các dự đoán và giải thích kết quả như thể một số opcode đã được kết hợp
  2. Tắt dự đoán để bộ đếm tần số opcode cập nhật cho cả hai opcode

Dự đoán opcode bị vô hiệu hóa với mã luồng vì mã sau cho phép CPU ghi lại thông tin dự đoán nhánh riêng cho từng opcode

Một số thao tác, chẳng hạn như

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
896,
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
897, có một đối số thao tác tham chiếu đến một hàm được biên dịch khác. Trong những trường hợp này, một khung khác được đẩy vào ngăn xếp khung trong luồng và vòng lặp đánh giá được chạy cho chức năng đó cho đến khi chức năng hoàn thành. Mỗi khi một khung hình mới được tạo và đẩy vào ngăn xếp, giá trị của khung hình
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
898 được đặt thành khung hình hiện tại trước khi khung hình mới được tạo

Việc lồng các khung này sẽ rõ ràng khi bạn nhìn thấy dấu vết ngăn xếp, hãy lấy tập lệnh ví dụ này

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
23

Gọi cái này trên dòng lệnh sẽ cung cấp cho bạn

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
24

Trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
899, hàm
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
900 được sử dụng để in dấu vết ngược lại

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
25

Ở đây, bạn có thể thấy rằng khung hiện tại, được tìm nạp bằng cách gọi

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
901 và cha của cha mẹ được đặt làm khung, bởi vì bạn không muốn thấy lệnh gọi tới
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
900 hoặc
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
903 trong quá trình theo dõi, vì vậy các khung chức năng đó sẽ bị bỏ qua

Sau đó, con trỏ

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
898 được đưa lên đầu

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
901 là API Python để lấy thuộc tính
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
906 của chuỗi hiện tại

Đây là giao diện trực quan của ngăn xếp khung đó, với 3 khung, mỗi khung có đối tượng mã của nó và trạng thái luồng trỏ đến khung hiện tại

Phần kết luận

Trong Phần này, bạn đã khám phá yếu tố phức tạp nhất của CPython. trình biên dịch. Tác giả đầu tiên của Python, Guido van Rossum, đã tuyên bố rằng trình biên dịch của CPython nên "câm" để mọi người có thể hiểu được nó

Bằng cách chia nhỏ quá trình biên dịch thành các bước nhỏ hợp lý, nó sẽ dễ hiểu hơn nhiều

Trong chương tiếp theo, chúng tôi kết nối quá trình biên dịch với cơ sở của tất cả các mã Python,

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
907

Phần 4. Các đối tượng trong Python

CPython đi kèm với một tập hợp các loại cơ bản như chuỗi, danh sách, bộ dữ liệu, từ điển và đối tượng

Tất cả các loại này đều được tích hợp sẵn. Bạn không cần nhập bất kỳ thư viện nào, kể cả từ thư viện chuẩn. Ngoài ra, việc khởi tạo các loại tích hợp này có một số phím tắt tiện dụng

Ví dụ, để tạo một danh sách mới, bạn có thể gọi

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
26

Hoặc, bạn có thể sử dụng dấu ngoặc vuông

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
27

Các chuỗi có thể được khởi tạo từ một chuỗi ký tự bằng cách sử dụng dấu ngoặc kép hoặc dấu ngoặc đơn. Chúng tôi đã khám phá các định nghĩa ngữ pháp trước đó khiến trình biên dịch diễn giải các dấu ngoặc kép dưới dạng một chuỗi ký tự

Tất cả các kiểu trong Python kế thừa từ

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
907, một kiểu cơ sở tích hợp sẵn. Ngay cả các chuỗi, bộ dữ liệu và danh sách kế thừa từ
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
907. Trong quá trình xem qua mã C, bạn đã đọc rất nhiều tài liệu tham khảo về
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
622, cấu trúc C-API cho một
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
907

Vì C không hướng đối tượng như Python nên các đối tượng trong C không kế thừa lẫn nhau.

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
301 là cấu trúc dữ liệu cho phần đầu bộ nhớ của đối tượng Python

Phần lớn API đối tượng cơ sở được khai báo trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
625, giống như hàm , mà hàm
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
915 tích hợp sẵn. Bạn cũng sẽ tìm thấy và các API khác

Tất cả các chức năng này có thể được ghi đè trong một đối tượng tùy chỉnh bằng cách triển khai các phương thức "dunder" trên một đối tượng Python

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
28

Mã này được triển khai trong , bên trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
625. Loại của đối tượng đích,
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
855 sẽ được suy ra thông qua lệnh gọi đến và nếu trường
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
921 được đặt, thì con trỏ hàm được gọi. Nếu trường
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
921 không được đặt, tôi. e. đối tượng không khai báo phương thức
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
923 tùy chỉnh, thì hành vi mặc định được chạy, đó là trả về
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
924 với tên loại và ID

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
29

Trường ob_type cho một

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
622 nhất định sẽ trỏ đến cấu trúc dữ liệu
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
926, được xác định trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
927. Cấu trúc dữ liệu này liệt kê tất cả các hàm dựng sẵn, dưới dạng các trường và đối số mà chúng sẽ nhận được

Lấy

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
921 làm ví dụ

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
30

Trong đó

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
929 là một
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
930 cho
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
931, một hàm lấy 1 con trỏ tới
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
301 [
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
933]

Một số API dunder là tùy chọn, vì chúng chỉ áp dụng cho một số loại nhất định, chẳng hạn như số

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
31

Một trình tự, giống như một danh sách sẽ thực hiện các phương pháp sau

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
32

Tất cả các chức năng tích hợp này được gọi là Mô hình dữ liệu Python. Một trong những tài nguyên tuyệt vời cho Mô hình dữ liệu Python là “Fluent Python” của Luciano Ramalho

Loại đối tượng cơ sở

Trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
625, việc triển khai cơ sở của loại
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
907 được viết dưới dạng mã C thuần túy. Có một số triển khai cụ thể của logic cơ bản, như so sánh nông

Không phải tất cả các phương thức trong đối tượng Python đều là một phần của Mô hình dữ liệu, do đó đối tượng Python có thể chứa các thuộc tính [thuộc tính lớp hoặc thuộc tính thể hiện] và phương thức

Một cách đơn giản để nghĩ về một đối tượng Python bao gồm 2 thứ

  1. Mô hình dữ liệu cốt lõi, với các con trỏ tới các hàm được biên dịch
  2. Một từ điển với bất kỳ thuộc tính và phương thức tùy chỉnh nào

Mô hình dữ liệu cốt lõi được xác định trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
926 và các chức năng được xác định trong

  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    625 cho các phương thức tích hợp
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    938 cho loại
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    939
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    940 cho loại
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    941
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    942 cho loại
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    393
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    944 cho loại
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    945
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    946 cho loại
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    947 trừu tượng, được sử dụng trong lập trình meta
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    948 được sử dụng cho loại đối tượng
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    949 tích hợp
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    950 cho một loại số phức tạp
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    951 cho một trình vòng lặp
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    887 cho loại
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    885
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    954 cho loại số
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    955
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    956 cho loại bộ nhớ cơ sở
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    957 cho loại phương thức lớp
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    958 cho loại mô-đun
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    959 cho một loại không gian tên
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    960 cho một loại từ điển được đặt hàng
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    961 cho bộ tạo phạm vi
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    962 cho loại
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    963
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    964 cho loại tham chiếu lát cắt
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    965 cho một loại
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    967 cho loại
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    968
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    969 cho loại
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    970
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    387 cho loại
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    390
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    973 cho một đối tượng
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    974

Chúng ta sẽ đi sâu vào 3 loại này

  1. Booleans
  2. số nguyên
  3. máy phát điện

Booleans và Integers có nhiều điểm chung, vì vậy chúng tôi sẽ đề cập đến những điểm đó trước

Kiểu số nguyên Bool và dài

Loại

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
939 là cách triển khai đơn giản nhất trong số các loại tích hợp. Nó kế thừa từ
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
955 và có các hằng số được xác định trước, và. Các hằng số này là các thể hiện bất biến, được tạo khi khởi tạo trình thông dịch Python

Bên trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
938, bạn có thể thấy hàm trợ giúp để tạo một phiên bản
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
939 từ một số

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
33

Hàm này sử dụng đánh giá C của một loại số để gán

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
977 hoặc
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
978 cho một kết quả và tăng bộ đếm tham chiếu

Các hàm số cho

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
983,
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
984 và
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
985 được triển khai, nhưng phép cộng, phép trừ và phép chia không được tham chiếu từ kiểu cơ sở dài vì sẽ không có ý nghĩa gì khi chia hai giá trị boolean

Việc triển khai

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
983 cho giá trị
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
939 sẽ kiểm tra xem
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
848 và
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
853 có phải là booleans hay không, sau đó kiểm tra tham chiếu của chúng tới
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
977, nếu không, được truyền dưới dạng số và thao tác
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
983 được chạy trên hai số

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
34

Loại

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
955 phức tạp hơn một chút vì yêu cầu bộ nhớ mở rộng. Trong quá trình chuyển đổi từ Python 2 sang Python 3, CPython đã bỏ hỗ trợ cho loại
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
908 và thay vào đó sử dụng loại
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
955 làm loại số nguyên chính. Kiểu
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
955 của Python khá đặc biệt ở chỗ nó có thể lưu trữ một số có độ dài thay đổi. Độ dài tối đa được đặt trong tệp nhị phân đã biên dịch

Cấu trúc dữ liệu của Python

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
955 bao gồm tiêu đề
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
301 và danh sách các chữ số. Danh sách các chữ số,
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
998 ban đầu được đặt thành một chữ số, nhưng sau đó được mở rộng thành độ dài dài hơn khi được khởi tạo

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
35

Bộ nhớ được phân bổ cho một

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
955 mới thông qua. Hàm này có độ dài cố định và đảm bảo rằng nó nhỏ hơn
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
001. Sau đó, nó phân bổ lại bộ nhớ cho
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
998 để phù hợp với độ dài

Để chuyển đổi loại C

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
955 thành loại Python
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
955,
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
955 được chuyển đổi thành danh sách các chữ số, bộ nhớ cho Python
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
955 được chỉ định, sau đó từng chữ số được đặt. Bởi vì
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
955 được khởi tạo với
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
998 đã có độ dài là 1, nếu số nhỏ hơn 10 thì giá trị được đặt mà không cần cấp phát bộ nhớ

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
36

Để chuyển đổi một dấu phẩy động hai dấu phẩy thành một Python

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
955,
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
010 sẽ thực hiện phép toán cho bạn

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
37

Phần còn lại của các chức năng triển khai trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
011 có các tiện ích, chẳng hạn như chuyển đổi một chuỗi Unicode thành một số với

Đánh giá về loại máy phát điện

Trình tạo Python là các hàm trả về câu lệnh

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
013 và có thể được gọi liên tục để tạo thêm giá trị

Thông thường, chúng được sử dụng như một cách hiệu quả hơn về bộ nhớ để lặp qua các giá trị trong một khối dữ liệu lớn, như tệp, cơ sở dữ liệu hoặc qua mạng

Các đối tượng trình tạo được trả về thay cho giá trị khi sử dụng

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
013 thay vì
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
656. Đối tượng trình tạo được tạo từ câu lệnh
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
013 và được trả lại cho người gọi

Hãy tạo một trình tạo đơn giản với danh sách 4 giá trị không đổi

>>>

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
38

Nếu bạn khám phá nội dung của đối tượng trình tạo, bạn có thể thấy một số trường bắt đầu bằng

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
017

>>>

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
39

Loại

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
018 được xác định trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
019 và có 3 hương vị

  1. đối tượng máy phát điện
  2. đối tượng quy trình
  3. Đối tượng trình tạo không đồng bộ

Cả 3 chia sẻ cùng một tập hợp con các trường được sử dụng trong trình tạo và có các hành vi tương tự nhau

Tập trung đầu tiên vào máy phát điện, bạn có thể thấy các trường

  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    020 liên kết với một
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    021 cho trình tạo, trước đó trong chương thực thi, chúng ta đã khám phá việc sử dụng cục bộ và toàn cục bên trong ngăn xếp giá trị của khung. Đây là cách trình tạo ghi nhớ giá trị cuối cùng của các biến cục bộ do khung liên tục giữa các lần gọi
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    022 được đặt thành 0 hoặc 1 nếu trình tạo hiện đang chạy
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    023 liên kết với một
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    520 với chức năng được biên dịch mang lại trình tạo để nó có thể được gọi lại
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    025 liên kết đến danh sách các tham chiếu yếu đến các đối tượng bên trong hàm tạo
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    026 là tên của trình tạo
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    027 là tên đủ điều kiện của trình tạo
  • cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    028 dưới dạng bộ dữ liệu ngoại lệ nếu lệnh gọi trình tạo phát sinh ngoại lệ

Coroutine và có các trường giống nhau nhưng được thêm vào trước bởi

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
029 và
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
030 tương ứng

Nếu bạn gọi

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
031 trên đối tượng trình tạo, giá trị tiếp theo sẽ được tạo ra cho đến khi cuối cùng một
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
032 được nâng lên

>>>

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
40

Mỗi khi

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
031 được gọi, đối tượng mã bên trong trường
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
023 của trình tạo được thực thi dưới dạng một khung mới và giá trị trả về được đẩy vào ngăn xếp giá trị

Bạn cũng có thể thấy rằng

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
023 là đối tượng mã được biên dịch cho hàm tạo bằng cách nhập mô-đun
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
574 và phân tách mã byte bên trong

>>>

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
41

Bất cứ khi nào

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
031 được gọi trên một đối tượng trình tạo, được gọi với đối tượng trình tạo, ngay lập tức gọi bên trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
040

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
039 là hàm chuyển đổi một đối tượng trình tạo thành kết quả mang lại tiếp theo. Bạn sẽ thấy nhiều điểm tương đồng với cách các khung được xây dựng trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
682 từ một đối tượng mã vì các chức năng này có nhiệm vụ tương tự nhau

Hàm

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
039 được chia sẻ với trình tạo, coroutines và trình tạo không đồng bộ và có các bước sau

  1. Trạng thái luồng hiện tại được tìm nạp

  2. Đối tượng khung từ đối tượng trình tạo được tìm nạp

  3. Nếu trình tạo đang chạy khi

    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    031 được gọi, hãy tăng
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    045

  4. Nếu khung bên trong trình tạo nằm ở trên cùng của ngăn xếp

    • Trong trường hợp của một coroutine, nếu coroutine chưa được đánh dấu là đóng, một
      cpython/
      │
      ├── Doc      ← Source for the documentation
      ├── Grammar  ← The computer-readable language definition
      ├── Include  ← The C header files
      ├── Lib      ← Standard library modules written in Python
      ├── Mac      ← macOS support files
      ├── Misc     ← Miscellaneous files
      ├── Modules  ← Standard Library Modules written in C
      ├── Objects  ← Core types and the object model
      ├── Parser   ← The Python parser source code
      ├── PC       ← Windows build support files
      ├── PCbuild  ← Windows build support files for older Windows versions
      ├── Programs ← Source code for the python executable and other binaries
      ├── Python   ← The CPython interpreter source code
      └── Tools    ← Standalone tools useful for building or extending Python
      
      046 sẽ xuất hiện
    • Nếu đây là một trình tạo không đồng bộ, hãy tăng
      cpython/
      │
      ├── Doc      ← Source for the documentation
      ├── Grammar  ← The computer-readable language definition
      ├── Include  ← The C header files
      ├── Lib      ← Standard library modules written in Python
      ├── Mac      ← macOS support files
      ├── Misc     ← Miscellaneous files
      ├── Modules  ← Standard Library Modules written in C
      ├── Objects  ← Core types and the object model
      ├── Parser   ← The Python parser source code
      ├── PC       ← Windows build support files
      ├── PCbuild  ← Windows build support files for older Windows versions
      ├── Programs ← Source code for the python executable and other binaries
      ├── Python   ← The CPython interpreter source code
      └── Tools    ← Standalone tools useful for building or extending Python
      
      047
    • Đối với một trình tạo tiêu chuẩn, một
      cpython/
      │
      ├── Doc      ← Source for the documentation
      ├── Grammar  ← The computer-readable language definition
      ├── Include  ← The C header files
      ├── Lib      ← Standard library modules written in Python
      ├── Mac      ← macOS support files
      ├── Misc     ← Miscellaneous files
      ├── Modules  ← Standard Library Modules written in C
      ├── Objects  ← Core types and the object model
      ├── Parser   ← The Python parser source code
      ├── PC       ← Windows build support files
      ├── PCbuild  ← Windows build support files for older Windows versions
      ├── Programs ← Source code for the python executable and other binaries
      ├── Python   ← The CPython interpreter source code
      └── Tools    ← Standalone tools useful for building or extending Python
      
      032 được nâng lên
  5. Nếu lệnh cuối cùng trong khung [

    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    049] vẫn là -1 vì nó mới được bắt đầu và đây là trình tạo coroutine hoặc async, thì không thể chuyển giá trị non-None làm đối số, do đó, một ngoại lệ sẽ được đưa ra

  6. Khác, đây là lần đầu tiên nó được gọi và các đối số được cho phép. Giá trị của đối số được đẩy vào ngăn xếp giá trị của khung

  7. Trường

    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    898 của khung là trình gọi mà các giá trị trả về được gửi đến, do đó, trường này được đặt thành khung hiện tại trong chuỗi. Điều này có nghĩa là giá trị trả về được gửi đến người gọi, không phải người tạo trình tạo

  8. Trình tạo được đánh dấu là đang chạy

  9. Ngoại lệ cuối cùng trong thông tin ngoại lệ của trình tạo được sao chép từ ngoại lệ cuối cùng trong trạng thái luồng

  10. Thông tin ngoại lệ trạng thái luồng được đặt thành địa chỉ thông tin ngoại lệ của trình tạo. Điều này có nghĩa là nếu người gọi nhập điểm dừng xung quanh việc thực thi trình tạo, thì dấu vết ngăn xếp sẽ đi qua trình tạo và mã vi phạm sẽ bị xóa

  11. Khung bên trong trình tạo được thực thi trong vòng lặp thực thi chính của

    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    682 và giá trị được trả về

  12. Ngoại lệ cuối cùng của trạng thái luồng được đặt lại thành giá trị trước khi khung được gọi

  13. Trình tạo được đánh dấu là không chạy

  14. Sau đó, các trường hợp sau khớp với giá trị trả về và bất kỳ ngoại lệ nào được đưa ra bởi lệnh gọi đến trình tạo. Hãy nhớ rằng các trình tạo sẽ tăng

    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    032 khi chúng cạn kiệt, theo cách thủ công hoặc bằng cách không mang lại giá trị. Các trình tạo coroutines và async không nên

    • Nếu không có kết quả nào được trả về từ khung, hãy tăng
      cpython/
      │
      ├── Doc      ← Source for the documentation
      ├── Grammar  ← The computer-readable language definition
      ├── Include  ← The C header files
      ├── Lib      ← Standard library modules written in Python
      ├── Mac      ← macOS support files
      ├── Misc     ← Miscellaneous files
      ├── Modules  ← Standard Library Modules written in C
      ├── Objects  ← Core types and the object model
      ├── Parser   ← The Python parser source code
      ├── PC       ← Windows build support files
      ├── PCbuild  ← Windows build support files for older Windows versions
      ├── Programs ← Source code for the python executable and other binaries
      ├── Python   ← The CPython interpreter source code
      └── Tools    ← Standalone tools useful for building or extending Python
      
      032 cho trình tạo và
      cpython/
      │
      ├── Doc      ← Source for the documentation
      ├── Grammar  ← The computer-readable language definition
      ├── Include  ← The C header files
      ├── Lib      ← Standard library modules written in Python
      ├── Mac      ← macOS support files
      ├── Misc     ← Miscellaneous files
      ├── Modules  ← Standard Library Modules written in C
      ├── Objects  ← Core types and the object model
      ├── Parser   ← The Python parser source code
      ├── PC       ← Windows build support files
      ├── PCbuild  ← Windows build support files for older Windows versions
      ├── Programs ← Source code for the python executable and other binaries
      ├── Python   ← The CPython interpreter source code
      └── Tools    ← Standalone tools useful for building or extending Python
      
      047 cho trình tạo không đồng bộ
    • Nếu một
      cpython/
      │
      ├── Doc      ← Source for the documentation
      ├── Grammar  ← The computer-readable language definition
      ├── Include  ← The C header files
      ├── Lib      ← Standard library modules written in Python
      ├── Mac      ← macOS support files
      ├── Misc     ← Miscellaneous files
      ├── Modules  ← Standard Library Modules written in C
      ├── Objects  ← Core types and the object model
      ├── Parser   ← The Python parser source code
      ├── PC       ← Windows build support files
      ├── PCbuild  ← Windows build support files for older Windows versions
      ├── Programs ← Source code for the python executable and other binaries
      ├── Python   ← The CPython interpreter source code
      └── Tools    ← Standalone tools useful for building or extending Python
      
      032 đã được nâng lên một cách rõ ràng, nhưng đây là một trình tạo coroutine hoặc một trình tạo không đồng bộ, hãy tăng một
      cpython/
      │
      ├── Doc      ← Source for the documentation
      ├── Grammar  ← The computer-readable language definition
      ├── Include  ← The C header files
      ├── Lib      ← Standard library modules written in Python
      ├── Mac      ← macOS support files
      ├── Misc     ← Miscellaneous files
      ├── Modules  ← Standard Library Modules written in C
      ├── Objects  ← Core types and the object model
      ├── Parser   ← The Python parser source code
      ├── PC       ← Windows build support files
      ├── PCbuild  ← Windows build support files for older Windows versions
      ├── Programs ← Source code for the python executable and other binaries
      ├── Python   ← The CPython interpreter source code
      └── Tools    ← Standalone tools useful for building or extending Python
      
      046 vì điều này không được phép
    • Nếu một
      cpython/
      │
      ├── Doc      ← Source for the documentation
      ├── Grammar  ← The computer-readable language definition
      ├── Include  ← The C header files
      ├── Lib      ← Standard library modules written in Python
      ├── Mac      ← macOS support files
      ├── Misc     ← Miscellaneous files
      ├── Modules  ← Standard Library Modules written in C
      ├── Objects  ← Core types and the object model
      ├── Parser   ← The Python parser source code
      ├── PC       ← Windows build support files
      ├── PCbuild  ← Windows build support files for older Windows versions
      ├── Programs ← Source code for the python executable and other binaries
      ├── Python   ← The CPython interpreter source code
      └── Tools    ← Standalone tools useful for building or extending Python
      
      047 đã được tăng lên một cách rõ ràng và đây là một trình tạo không đồng bộ, hãy tăng một
      cpython/
      │
      ├── Doc      ← Source for the documentation
      ├── Grammar  ← The computer-readable language definition
      ├── Include  ← The C header files
      ├── Lib      ← Standard library modules written in Python
      ├── Mac      ← macOS support files
      ├── Misc     ← Miscellaneous files
      ├── Modules  ← Standard Library Modules written in C
      ├── Objects  ← Core types and the object model
      ├── Parser   ← The Python parser source code
      ├── PC       ← Windows build support files
      ├── PCbuild  ← Windows build support files for older Windows versions
      ├── Programs ← Source code for the python executable and other binaries
      ├── Python   ← The CPython interpreter source code
      └── Tools    ← Standalone tools useful for building or extending Python
      
      046, vì điều này không được phép
  15. Cuối cùng, kết quả được trả lại cho người gọi của

    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    031

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
42

Quay trở lại việc đánh giá các đối tượng mã bất cứ khi nào một hàm hoặc mô-đun được gọi, có một trường hợp đặc biệt đối với các trình tạo, coroutines và trình tạo không đồng bộ trong. Hàm này kiểm tra các cờ

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
061,
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
062 và
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
063 trên đối tượng mã

Khi một coroutine mới được tạo bằng cách sử dụng, một trình tạo không đồng bộ mới được tạo bằng hoặc một trình tạo bằng. Các đối tượng này được trả về sớm thay vì trả về một khung đã đánh giá, đó là lý do tại sao bạn nhận được một đối tượng trình tạo sau khi gọi một hàm bằng câu lệnh suất

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
43

Các cờ trong đối tượng mã đã được trình biên dịch đưa vào sau khi duyệt qua AST và nhìn thấy các câu lệnh

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
013 hoặc
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
068 hoặc nhìn thấy trình trang trí
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
069

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
066 sẽ gọi với khung được tạo và sau đó tạo
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
018 với các giá trị
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
073 và đối tượng mã được biên dịch

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
44

Kết hợp tất cả những điều này lại với nhau, bạn có thể thấy biểu thức trình tạo là một cú pháp mạnh mẽ như thế nào trong đó một từ khóa duy nhất,

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
013 kích hoạt toàn bộ luồng để tạo một đối tượng duy nhất, sao chép một đối tượng mã đã biên dịch làm thuộc tính, đặt khung và lưu trữ danh sách các biến

Đối với người sử dụng biểu thức trình tạo, tất cả điều này có vẻ giống như ma thuật, nhưng dưới vỏ bọc thì nó không phức tạp lắm

Phần kết luận

Bây giờ bạn đã hiểu cách một số loại tích hợp sẵn, bạn có thể khám phá các loại khác

Khi khám phá các lớp Python, điều quan trọng cần nhớ là có các loại dựng sẵn, được viết bằng C và các lớp kế thừa từ các loại đó, được viết bằng Python hoặc C

Một số thư viện có các kiểu được viết bằng C thay vì kế thừa từ các kiểu dựng sẵn. Một ví dụ là

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
075, một thư viện cho các mảng số. Loại
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
076 được viết bằng C, hiệu quả cao và hoạt động hiệu quả

Phần tiếp theo chúng ta sẽ tìm hiểu các lớp và hàm được định nghĩa trong thư viện chuẩn

Phần 5. Thư viện chuẩn Python

Python đã luôn đi kèm với “pin đi kèm. ” Tuyên bố này có nghĩa là với bản phân phối CPython tiêu chuẩn, có các thư viện để làm việc với tệp, luồng, mạng, trang web, nhạc, bàn phím, màn hình, văn bản và toàn bộ tiện ích

Một số pin đi kèm với CPython giống pin AA hơn. Chúng hữu ích cho mọi thứ, như mô-đun

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
077 và mô-đun
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
078. Một số trong số chúng khó hiểu hơn một chút, chẳng hạn như pin đồng hồ nhỏ mà bạn không bao giờ biết khi nào nó có thể hữu ích

Có 2 loại module trong thư viện chuẩn của Python

  1. Những thứ được viết bằng Python thuần túy cung cấp tiện ích
  2. Những thứ được viết bằng C với trình bao bọc Python

Chúng ta sẽ khám phá cả hai loại

Mô-đun Python

Các mô-đun được viết bằng Python thuần túy đều nằm trong thư mục

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
079 trong mã nguồn. Một số mô-đun lớn hơn có các mô-đun con trong các thư mục con, chẳng hạn như mô-đun
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
080

Một mô-đun dễ xem sẽ là mô-đun

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
081. Nó chỉ có vài trăm dòng mã Python. Có thể bạn chưa gặp nó trước đây. Mô-đun
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
081 có một số chức năng tiện ích để chuyển đổi thang màu

Khi bạn cài đặt bản phân phối Python từ nguồn, các mô-đun thư viện tiêu chuẩn được sao chép từ thư mục

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
083 vào thư mục phân phối. Thư mục này luôn là một phần trong đường dẫn của bạn khi bạn khởi động Python, vì vậy bạn có thể
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
084 các mô-đun mà không phải lo lắng về vị trí của chúng

Ví dụ

>>>

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
45

Chúng ta có thể thấy mã nguồn của ________ 0085 bên trong ________ 0086

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
46

Không có gì đặc biệt về chức năng này, nó chỉ là Python tiêu chuẩn. Bạn sẽ tìm thấy những thứ tương tự với tất cả các mô-đun thư viện chuẩn Python thuần túy. Chúng chỉ được viết bằng Python đơn giản, bố cục tốt và dễ hiểu. Bạn thậm chí có thể phát hiện ra các cải tiến hoặc lỗi, vì vậy bạn có thể thay đổi chúng và đóng góp vào bản phân phối Python. Chúng tôi sẽ đề cập đến điều đó vào cuối bài viết này

Mô-đun Python và C

Phần còn lại của các mô-đun được viết bằng C hoặc kết hợp hoặc Python và C. Mã nguồn của những thứ này nằm trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
079 cho thành phần Python và
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
088 cho thành phần C. Có hai trường hợp ngoại lệ đối với quy tắc này, mô-đun
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
078, được tìm thấy trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
090 và mô-đun
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
091, được tìm thấy trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
092

Python sẽ

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
093 khi trình thông dịch được khởi tạo, vì vậy tất cả các hàm như , , , v.v. được tìm thấy trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
092

Bởi vì mô-đun

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
078 rất dành riêng cho trình thông dịch và phần bên trong của CPython, được tìm thấy trực tiếp bên trong
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
113. Nó cũng được đánh dấu là "chi tiết triển khai" của CPython và không tìm thấy trong các bản phân phối khác

Hàm

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
094 tích hợp có lẽ là điều đầu tiên bạn học được trong Python. Vậy điều gì xảy ra khi bạn gõ
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
101?

  1. Đối số
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    102 đã được trình biên dịch chuyển đổi từ hằng chuỗi thành
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    103
  2. cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    104 đã được thực thi với 1 đối số và NULL
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    802
  3. Biến
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    106 được đặt thành
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    107, bộ điều khiển
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    108 của hệ thống
  4. Mỗi đối số được gửi đến
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    106
  5. Ngắt dòng,
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    110 được gửi đến
    cpython/
    │
    ├── Doc      ← Source for the documentation
    ├── Grammar  ← The computer-readable language definition
    ├── Include  ← The C header files
    ├── Lib      ← Standard library modules written in Python
    ├── Mac      ← macOS support files
    ├── Misc     ← Miscellaneous files
    ├── Modules  ← Standard Library Modules written in C
    ├── Objects  ← Core types and the object model
    ├── Parser   ← The Python parser source code
    ├── PC       ← Windows build support files
    ├── PCbuild  ← Windows build support files for older Windows versions
    ├── Programs ← Source code for the python executable and other binaries
    ├── Python   ← The CPython interpreter source code
    └── Tools    ← Standalone tools useful for building or extending Python
    
    106

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
47

Nội dung của một số mô-đun được viết bằng C hiển thị các chức năng của hệ điều hành. Do mã nguồn CPython cần biên dịch sang macOS, Windows, Linux và các hệ điều hành dựa trên *nix khác nên có một số trường hợp đặc biệt

Mô-đun

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
112 là một ví dụ điển hình. Cách Windows giữ và lưu trữ thời gian trong Hệ điều hành về cơ bản khác với Linux và macOS. Đây là một trong những lý do tại sao độ chính xác của các chức năng đồng hồ khác nhau

Trong

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
113, các chức năng thời gian của hệ điều hành cho các hệ thống dựa trên Unix được nhập từ
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
114

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
48

Sau này trong tệp,

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
115 được định nghĩa là trình bao bọc cho
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
116

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
49

được triển khai theo nhiều cách khác nhau trong mã nguồn, nhưng chỉ một số phần nhất định được biên dịch thành tệp nhị phân cho mô-đun, tùy thuộc vào hệ điều hành. Hệ thống Windows sẽ gọi ________ 0118 và hệ thống Unix sẽ gọi ________ 0119

Các mô-đun khác có nhiều triển khai cho cùng một API là mô-đun luồng, mô-đun hệ thống tệp và mô-đun mạng. Do các Hệ điều hành hoạt động khác nhau, nên mã nguồn CPython thực hiện cùng một hành vi tốt nhất có thể và hiển thị nó bằng cách sử dụng API trừu tượng, nhất quán

Bộ kiểm tra hồi quy CPython

CPython có bộ thử nghiệm mạnh mẽ và mở rộng bao gồm trình thông dịch lõi, thư viện chuẩn, công cụ và phân phối cho cả Windows và Linux/macOS

Bộ thử nghiệm được đặt tại

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
120 và được viết gần như hoàn toàn bằng Python

Bộ thử nghiệm đầy đủ là một gói Python, vì vậy có thể chạy bằng trình thông dịch Python mà bạn đã biên dịch. Thay đổi thư mục thành thư mục

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
083 và chạy
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
122, trong đó
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
123 có nghĩa là sử dụng 2 CPU

Trên Windows, sử dụng tập lệnh

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
124 bên trong thư mục PCBuild, đảm bảo rằng bạn đã xây dựng trước cấu hình Phát hành từ Visual Studio

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
50

Trên Linux

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
51

Trên macOS

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
52

Một số bài kiểm tra yêu cầu một số cờ nhất định; . Ví dụ: nhiều bài kiểm tra IDLE yêu cầu GUI

Để xem danh sách các bộ thử nghiệm trong cấu hình, hãy sử dụng cờ

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
125

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
53

Bạn có thể chạy các thử nghiệm cụ thể bằng cách cung cấp bộ thử nghiệm làm đối số đầu tiên

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
54

Bạn cũng có thể xem danh sách chi tiết các bài kiểm tra đã được thực hiện với kết quả bằng cách sử dụng đối số

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
356

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
55

Hiểu cách sử dụng bộ kiểm tra và kiểm tra trạng thái của phiên bản bạn đã biên dịch là rất quan trọng nếu bạn muốn thay đổi CPython. Trước khi bắt đầu thực hiện các thay đổi, bạn nên chạy toàn bộ bộ thử nghiệm và đảm bảo mọi thứ đều ổn

Cài đặt phiên bản tùy chỉnh

Từ kho lưu trữ nguồn của bạn, nếu bạn hài lòng với những thay đổi của mình và muốn sử dụng chúng bên trong hệ thống của mình, bạn có thể cài đặt nó dưới dạng phiên bản tùy chỉnh

Đối với macOS và Linux, bạn có thể sử dụng lệnh

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
127, lệnh này sẽ không tạo liên kết tượng trưng cho
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
128 và cài đặt phiên bản độc lập

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
56

Đối với Windows, bạn phải thay đổi cấu hình bản dựng từ

cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
129 thành
cpython/
│
├── Doc      ← Source for the documentation
├── Grammar  ← The computer-readable language definition
├── Include  ← The C header files
├── Lib      ← Standard library modules written in Python
├── Mac      ← macOS support files
├── Misc     ← Miscellaneous files
├── Modules  ← Standard Library Modules written in C
├── Objects  ← Core types and the object model
├── Parser   ← The Python parser source code
├── PC       ← Windows build support files
├── PCbuild  ← Windows build support files for older Windows versions
├── Programs ← Source code for the python executable and other binaries
├── Python   ← The CPython interpreter source code
└── Tools    ← Standalone tools useful for building or extending Python
130, sau đó sao chép các tệp nhị phân được đóng gói vào một thư mục trên máy tính của bạn. Đây là một phần của đường dẫn hệ thống

Mã nguồn CPython. Phần kết luận

Xin chúc mừng, bạn đã làm được. Trà của bạn có bị nguội không? . Bạn đã kiếm được nó

Bây giờ bạn đã thấy mã nguồn CPython, các mô-đun, trình biên dịch và công cụ, bạn có thể muốn thực hiện một số thay đổi và đóng góp chúng trở lại hệ sinh thái Python

Hướng dẫn dành cho nhà phát triển chính thức chứa nhiều tài nguyên dành cho người mới bắt đầu. Bạn đã thực hiện bước đầu tiên để hiểu mã nguồn, biết cách thay đổi, biên dịch và kiểm tra các ứng dụng CPython

Nghĩ lại tất cả những điều bạn đã học về CPython qua bài viết này. Tất cả những mảnh ma thuật mà bạn đã học được những bí mật. Cuộc hành trình không dừng lại ở đây

Đây có thể là thời điểm tốt để tìm hiểu thêm về Python và C. Ai biết. bạn có thể ngày càng đóng góp nhiều hơn cho dự án CPython. Ngoài ra, hãy nhớ xem cuốn sách CPython Internals mới có sẵn tại đây trên Real Python

Tải xuống miễn phí. Nhận một chương mẫu từ CPython Internals. Hướng dẫn về Trình thông dịch Python 3 chỉ cho bạn cách mở khóa hoạt động bên trong của ngôn ngữ Python, biên dịch trình thông dịch Python từ mã nguồn và tham gia phát triển CPython

Đánh dấu là đã hoàn thành

🐍 Thủ thuật Python 💌

Nhận một Thủ thuật Python ngắn và hấp dẫn được gửi đến hộp thư đến của bạn vài ngày một lần. Không có thư rác bao giờ. Hủy đăng ký bất cứ lúc nào. Được quản lý bởi nhóm Real Python

Gửi cho tôi thủ thuật Python »

Về Anthony Shaw

Anthony là một Pythonista cuồng nhiệt và viết cho Real Python. Anthony là thành viên của Python Software Foundation và là thành viên của Open-Source Apache Foundation

» Thông tin thêm về Anthony

Mỗi hướng dẫn tại Real Python được tạo bởi một nhóm các nhà phát triển để nó đáp ứng các tiêu chuẩn chất lượng cao của chúng tôi. Các thành viên trong nhóm đã làm việc trong hướng dẫn này là

Aldren

Jim

Joanna

Bậc thầy Kỹ năng Python trong thế giới thực Với quyền truy cập không giới hạn vào Python thực

Tham gia với chúng tôi và có quyền truy cập vào hàng nghìn hướng dẫn, khóa học video thực hành và cộng đồng các Pythonistas chuyên gia

Nâng cao kỹ năng Python của bạn »

Bậc thầy Kỹ năng Python trong thế giới thực
Với quyền truy cập không giới hạn vào Python thực

Tham gia với chúng tôi và có quyền truy cập vào hàng ngàn hướng dẫn, khóa học video thực hành và cộng đồng Pythonistas chuyên gia

Nâng cao kỹ năng Python của bạn »

Bạn nghĩ sao?

Đánh giá bài viết này

Tweet Chia sẻ Chia sẻ Email

Bài học số 1 hoặc điều yêu thích mà bạn đã học được là gì?

Mẹo bình luận. Những nhận xét hữu ích nhất là những nhận xét được viết với mục đích học hỏi hoặc giúp đỡ các sinh viên khác. và nhận câu trả lời cho các câu hỏi phổ biến trong cổng thông tin hỗ trợ của chúng tôi

Lấy mã nguồn Python ở đâu?

Chúng tôi sử dụng phương thức getsource[] để kiểm tra mô-đun để lấy mã nguồn của hàm. Trả về văn bản của mã nguồn cho một đối tượng. Đối số có thể là một mô-đun, lớp, phương thức, hàm, truy nguyên, khung hoặc đối tượng mã. Mã nguồn được trả về dưới dạng một chuỗi

Mã nguồn Python có sẵn không?

Mã nguồn Python và trình cài đặt có sẵn để tải xuống cho tất cả các phiên bản .

Chủ Đề