Skip to content

Installtion and Getting Started

:material-circle-edit-outline: 约 175 个字 :fontawesome-solid-code: 15 行代码 :material-clock-time-two-outline: 预计阅读时间 1 分钟

Writing and Running Python Scripts

#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
"""
hello: First Python Script
"""
myStr = 'Hello, world'  # Strings are enclosed in single quotes or double quotes
print(myStr)
myInt = 2 ** 88         # 2 to the power of 88. Python's integer is unlimited in size!
print(myInt)
myFloat = 8.01234567890123456789  # Python support floating-point numbers
print(myFloat)
myComplex = (1+2j) / (3-4j)  # Python supports complex numbers!
print(myComplex)        
myLst = [11, 22, 33]    # Python supports list (dynamic array)
print(myLst[1])
How it Works
  1. By convention, Python script (module) filenames are in all-lowercase (e.g., hello).
  2. EOL Comment: Statements beginning with a # until the end-of-line (EOL) are comments.
  3. #!/usr/bin/env python3 (Line 1) is applicable to the Unix environment only.
    1. It is known as the Hash-Bang (or She-Bang) for specifying the location of Python Interpreter, so that the script can be executed directly as a standalone program.
  4. # -*- coding: UTF-8 -*- (Line 2, optional) specifies the source encoding scheme for saving the source file.
    1. We choose and recommend UTF-8 for internationalization. This special format is recognized by many popular editors for saving the source code in the specified encoding format.
  5. """ hello ...... """ (Line 3-5): The script begins by the so-called doc-string to provide the documentation for this Python module.
    1. Doc-string is typically a multi-line string (delimited by triple-single or triple-double quoted), which can be extracted from the source file to create documentation.
  6. Python's integer is unlimited in size (Line 8).
  7. Python supports complex numbers (Line 12) and other high-level data types.