Python introductory tutorial | Python introduction and environment construction

Introduction to Python

Python is a high-level programming language created in 1991 by Dutchman Guido van Rossum. It is widely loved for its ease of learning, great readability, and rich ecosystem. It is widely used in various fields, including web development, scientific computing, data analysis, artificial intelligence, etc.

Features of Python

  • Concise and readable: Python adopts a clear and concise syntax, using indentation to denote code blocks, rather than relying on curly braces. This makes the code more readable and maintainable.

  • Cross-platform: Python can run on multiple operating systems, including Windows, Linux, Mac, etc., without modifying the code. This allows developers to easily develop and deploy applications on different platforms.

  • Powerful standard library: Python comes with a rich standard library covering modules for various common tasks such as file handling, network communication, database access, and more. Developers can directly use these modules, reducing duplication of work and improving development efficiency.

  • A large number of third-party libraries and frameworks: Python has a huge ecosystem of third-party libraries and frameworks, such as NumPy, Pandas, Django, Flask, etc. These libraries and frameworks provide developers with rich functions and tools to meet various needs, such as scientific computing, data analysis, web development, etc.

  • Object-Oriented Programming (OOP): Python is an object-oriented language that supports object-oriented programming concepts such as classes, objects, inheritance, and polymorphism. This programming paradigm makes code more modular, reusable, and understandable.

  • Dynamic typing and automatic memory management: Python is a dynamically typed language where the types of variables are determined automatically at runtime. At the same time, Python also has a garbage collection mechanism, which can automatically manage memory and reduce the memory management burden of developers.

  • Versatility and scalability: Python is suitable for a variety of tasks, including scripting, web development, data analysis, artificial intelligence, and more. Moreover, Python can be seamlessly integrated with other languages ​​(such as C/C++), providing good scalability.

Python development application

  • Youtube - video social networking site
  • Reddit - social sharing site
  • Dropbox - file sharing service
  • Douban.com - an information database website for cultural products such as books, records, and movies
  • Zhihu - a question and answer website
  • Nutshell - a general technology theme website
  • Bottle - Python micro web framework
  • EVE - The online game EVE uses Python extensively for development
  • Blender - Open source 3D drawing software using Python as a modeling tool and GUI language
  • Inkscape - An open source SVG vector graphics editor.

Python environment construction

Python3 is available on multiple platforms including Windows, Linux and Mac OS X.

Python download

The latest source code, binary documents, and news information of Python3 can be viewed on Python’s official website:
Python official website: https://www.python.org/
You can download Python documents from the following link, you can download HTML, PDF and PostScript documents in other formats.
Python document download address: https://www.python.org/doc/
Python SDK download address: https://www.python.org/downloads/

Python installation

Python has been ported (modified to make it work on different platforms) on many platforms.

You need to download the binaries for your platform and install Python.

If binaries are not available for your platform, you will need to manually compile the source code using a C compiler.

Compiled source code, more selective in functionality, provides more flexibility for Python installations.

The following are the download addresses of the installation packages for each platform :
insert image description here
Source Code can be used for installation on Linux. The following are the methods of installing Python
on different platforms .

Install Python on Unix & Linux platforms:

Here are the simple steps to install Python on Unix & Linux platforms:

  • Open a WEB browser and visit https://www.python.org/downloads/source/
  • Choose the source tarball for Unix/Linux.
  • Download and decompress the compressed package Python-3.xxtgz, where 3.xx is the corresponding version number you downloaded.
  • If you need to customize some options modify Modules/Setup

Take Python3.11.4 version as an example:

# tar -zxvf Python-3.11.4.tgz
# cd Python-3.11.4
# ./configure
# make && make install

Check that Python is available:

# python --version
Python 3.11.4

Install Python on Windows platform:

Following are the simple steps to install Python on Windows platform.

Open the WEB browser to visit https://www.python.org/downloads, click download, and the website will automatically download the installation package that matches the system.
insert image description here
Double-click the exe installation package, the installation interface will pop up, remember to check Add python.exe to PATH.
Then click Install Now to install

  • Install Now One-click installation for fools
  • Customize installation Custom installation, you can configure the installation directory and other information
    insert image description here
    Press the Win+R key, enter cmd to bring up the command prompt, enter python:
    insert image description here
    the above information pops up to indicate that the Python environment has been installed.

run python

There are three ways to run Python code:

1. Interactive interpreter:

Enter Python through the command line window and start writing Python code in the interactive interpreter.
You can do Python coding work on Unix, DOS, or any other system that provides a command line or shell.
Unix/Linux command window

$ python

Windows/Dos CMD command line window

C:\Users\liuya>python

2, command line script

Run the file script command written by python code:

python script.py 

3. Integrated Development Environment (IDE: Integrated Development Environment):

Commonly used Python code advanced editors include PyCharm and vscode (Visual Studio Code)

PyCharm:

PyCharm is a professional Python integrated development environment (IDE) developed by JetBrains. It provides a wealth of features and tools designed to improve the efficiency and quality of Python development.

main feature:

  • Complete development environment: PyCharm has comprehensive functions, including smart code completion, syntax highlighting, automatic refactoring, debugger, unit testing tools, etc. These features make it easier for developers to write, debug, and test code.
  • Focus on large projects: PyCharm is suitable for developing large projects and team collaboration. It provides powerful code navigation, version control integration and team collaboration tools, making multi-person collaborative development more convenient.
  • Built-in scientific computing and data analysis library support: PyCharm integrates many commonly used scientific computing and data analysis libraries, such as NumPy, Pandas, and Matplotlib. This makes data analysis and visualization in PyCharm much more convenient.

PyCharm download address: https://www.jetbrains.com/pycharm/download/

Visual Studio Code(VS Code):

Visual Studio Code is a lightweight cross-platform code editor developed by Microsoft. It is highly extensible and customizable, and can meet different development needs by installing plug-ins.

main feature:

  • Lightweight and fast: VS Code is a lightweight editor that starts up fast, responds quickly, and uses less system resources.
  • Powerful plug-in ecosystem: VS Code has a rich library of extended plug-ins, and users can install various plug-ins according to their needs, including Python-related plug-ins, such as code completion, debugger, Linters, etc.
  • Cross-platform support: VS Code can run on multiple operating systems such as Windows, Mac, and Linux, and provides a consistent user interface and functionality.

Vscode download address: https://visualstudio.microsoft.com/zh-hans/downloads/

Whether to choose PyCharm or VS Code depends on personal preference, project requirements and workflow. PyCharm is suitable for professional developers and large-scale projects, while VS Code is suitable for lightweight development and scenarios requiring scalability.

Guess you like

Origin blog.csdn.net/weixin_40986713/article/details/132394840