SoFunction
Updated on 2024-11-21

Detailed python learning notes of the interpreter

1. python tutorial

Ongoing interpretation based on python 3.10, designed for quick recall to deepen understanding and save yourself the cost of time

1.1 General

python is an easy-to-learn programming language that offers efficient high-level data structures, simple and effective object-oriented programming.
This is because the elegant syntax, dynamic typing, and interpreted nature of the language make it an ideal language for writing scripts and rapidly developing applications on most platforms. The following summaries are all based on the python10 expansion.

1.2 python standard library

A large number of modules written in Python that provide standard solutions to many problems in everyday programming.

/zh-cn/3/library/#library-index

The catalog is below:

Overview, built-in functions, built-in constants, built-in types, built-in exceptions,
Text processing services, binary data services, data types, numerical and mathematical modules, functional into modules, file and directory access, data persistence, data compression and archiving
File formats, encryption services, general-purpose operating system services, concurrent execution, network and inter-process communication, Internet data processing, structured markup processing tools, Internet protocols and support, multimedia services
Internationalization, Programming Framework, TK Graphical User Interface (GUI), Development Tools, Debugging and Analysis, Software Packaging and Distribution, Python Runtime Services, Custom Python Parser, Python Language Services
Imported modules, windows system related modules, Unix proprietary services, superseded modules,

1.3 python language reference manual

/zh-cn/3/reference/#reference-index

An introduction to the Python syntax and "core semantics". While trying to be concise, we have tried to be as accurate and complete as possible, with overviews, lexical analysis, data model, execution model, import system, expressions, simple statements, conforming statements, top-level components, and a complete syntax specification.

1.4 python package index

/

python tutorial

/zh-cn/3/tutorial/

This tutorial is not a complete introduction to every feature, and does not even cover all of the commonly used features; it only introduces the most worthwhile features in Python, and aims to give the reader a quick taste of what Python has to offer.
Readers who have completed this tutorial can read and write Python modules and programs, as well as move on to the Python standard library.

1.5 Glossary of terms

/zh-cn/3.10/#glossary

2. Dessert before class

Python is easy to use, but it's a real programming language, offering a large number of data structures and support for the development of large programs, far beyond shell scripts or batch files.

Python programs are concise, easy to read, and often much shorter than C, C++, or Java code that implements the same functionality, for the following reasons:

  • Advanced data types allow complex operations to be expressed in a single statement;
  • Use indentation, not parentheses, to implement code block grouping;
  • There is no need to pre-declare variables or parameters.

Python is "extensible": knowing how to develop C programs, you can quickly get up to speed on adding new built-in functions or modules to the interpreter, whether it's to make the core program run at top speed, or to link Python programs to libraries that provide only pre-compiled programs (e.g., hardware graphics libraries). With a little effort, you can link the Python interpreter to an application developed in C and use it to extend and control that application.

3. python parser

3.1 Incoming parameters

import sys

a = [0]
b = [1]
c = [2]


# Specify the value of language on the command line, and the file leaves the output language
if ("=")[0] == "language":
    c = ("=")[1]
    print("Value of the first string after the script:"+c)
else:
    print("Your first parameter name is not correct, it should be language.")

# The above three variables can be passed as arguments to functions in subsequent programs
def tiaoce(a, b, c):
    print("Script name:" + a)
    print("The first string after the script:" + b)
    print("The second string after the script:" + c)

tiaoce(a,b,c)

Anticipation:

C:\Users\mc\Desktop\pythoninfrastructural>python  language=jiao aa bb
The value of the first parameter after the script:jiao
Script name:
The first string after the script:language=jiao
The second brother string after the script:jiao

3.2 Interactive operation

C:\Users\mc>python
Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> aa = True
>>> if aa:
...     print("jiaotengfei")
...
jiaotengfei
>>>

3.2.1 Executable Python Scripts

Execution on linux: Python scripts can be executed directly, just like shell scripts, by adding on the first line.

#!/usr/bin/env python3.5
$ chmod +x 

Execute on windows 10: right click on the py file, choose python for the open mode, and double click on it to execute it automatically

print("jiao")
a = input("Please enter a message:")
print(a)

3.2.2 Interactive startup files

When you use Python interactively, it's often convenient to run some standard commands each time you start the interpreter. You can do this by setting an environment variable called PYTHONSTARTUP to the name of the file containing the startup commands. This is similar to the .profile function of the Unix shell.

import os

filename = ('ANDROID_HOME')
# Print the values of your environment variables.
print(filename)
# Expected
"""D:\Program Files\android-sdk-windows"""

filename = ('PYTHONSTARTUP')
print(filename)
if filename and (filename):
    with open(filename) as fobj:
        startup_file = ()
        print(startup_file)
    exec(startup_file)

3.3 Interpreter runtime environment (character encoding of source files)

By default, Python source files are encoded in UTF-8. If you don't use the default encoding, declare the file's encoding and write the first line of the file as a special comment. The syntax is as follows:

# encoding can be any of the codecs supported by Python.
# (This module defines the base classes for standard Python codecs (encoders and decoders))
# -*- coding: encoding -*-
# Declare the use of Windows-1252 encoding
# -*- coding: cp1252 -*-

Definition of the first line of an executable python file:

#!/usr/bin/env python3
# -*- coding: cp1252 -*-

summarize

That's all for this post, I hope it was helpful and I hope you'll check back for more from me!