Day 2 of Python language learning_First introduction to Python

I. Introduction

In today's digital age, programming languages ​​have become the cornerstone of innovation and technology. Among many programming languages, Python stands out for its unique charm and practicality, and has become the language of choice for software developers, data scientists and beginners around the world. Python's concise syntax, powerful standard library, and extensive community support make it a powerful tool for solving a variety of problems.

This chapter is the second chapter of the Python series. The previous chapter talked about building a compilation environment . The purpose of this chapter is to provide beginners with a comprehensive and intuitive understanding of the Python programming language.

1. Introduction to the Python programming language

Python is a high-level, interpreted, general-purpose programming language. It was created by Guido van Rossum in 1989 and has been continuously developed and improved over time. Python's design philosophy emphasizes code readability and concise syntax (especially the use of space indentation to distinguish code blocks), which makes it both easy to learn and easy to read.

2. Explain the popularity and uses of Python

The popularity of Python can be seen from its wide range of applications in many fields. Whether it is web development, data analysis, artificial intelligence, scientific computing or automation scripts, Python can provide powerful support. Its popularity is due in part to its vast standard library and third-party modules that provide tools and functionality for almost any task imaginable.

3. Programming language rankings and Python official documentation

3.1 TIOBE March TOP 20 programming languages

TIOBE

3.2 Python official documentation

Python3.12.2 official documentation

2. First introduction to Python

1. History and development of Python

1.1. Origin

Python was designed by Dutch programmer Guido van Rossum during the Christmas season of 1989. Guido Van Rossum's aim was to create a language that could solve real problems, be easy to read and understand, and also support multiple programming paradigms. The name Python comes from the British comedy group "Monty Python" that Guido van Rossum liked.

1.2. Early development

In 1991, the first official version of Python, 0.9.0, was released, supporting classes, functions, exception handling and other features. In 1994, Python 1.0 was released, introducing functional programming features such as lambda, map, filter and reduce. Python's design philosophy is "elegant", "clear" and "simple", which has been maintained during the development of Python.

1.3, Python 2.x series

In 2000, Python 2.0 was released, introducing new features such as garbage collection mechanism and list comprehension. In the following years, the Python community continued to grow, and the Python 2.x series underwent multiple updates, including versions 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, and 2.7. Python 2.7 version is the last major version of the 2.x series, released in 2010.

1.4, Python 3.x series

In 2008, Python 3.0 (also known as Python 3000 or Py3K) was released, which introduced a large number of language and library-level changes and was not fully backwards compatible with Python 2.x. The goal of Python 3 is to clean up some redundant and outdated features in the language and make the language more consistent and easier to learn. Although the migration process of Python 3 is relatively slow, new versions are continuously launched, including 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9 and the latest 3.10, etc., each version brings new features and Improve.

1.5. Community and Ecosystem

The development of Python benefits from its huge community support, and community members have contributed a large number of open source libraries and tools. Python's package index PyPI (Python Package Index) provides a large number of third-party libraries, allowing Python to be used in various fields. Python is widely used in scientific computing, data analysis, artificial intelligence, web development, automated testing, education and other fields.

1.6. Future prospects

Python's continued updates and improvements show that it is still an active and evolving language. As technology advances and new areas emerge, Python will likely continue to expand its scope of applications and add new features

2. Advantages

  • Easy to learn and use: Python has a highly readable syntax that is beginner-friendly, making the learning curve relatively gentle.
  • Rich standard library: Python comes with a large number of standard libraries, covering many functions such as network, file system, operating system interface, database connection, etc., which facilitates developers to quickly develop various applications.
  • Rich third-party libraries: Python has a huge number of third-party package resources (such as NumPy and Pandas for data analysis, Django for web development, TensorFlow for machine learning, etc.), which greatly expands the application scope of Python.
  • Cross-platform: Python can run on multiple operating systems such as Windows, Linux, and Mac OS, and has good portability.
  • High-level language features: automatic memory management, dynamic type system, garbage collection mechanism, etc., reduce the programmer's workload.
  • Extensive community support: Python has an active global developer community with abundant question answers, tutorial resources, and open source projects.

3. Python application fields

  • Web Development: Complex web applications can be built through frameworks such as Django and Flask.
  • Scientific computing and data analysis: widely used in scientific computing, statistical analysis, machine learning and other fields, such as libraries such as SciPy, NumPy, Pandas and Matplotlib.
  • Education: Python is often used in computer science teaching and primary programming education.
  • Artificial Intelligence and Machine Learning: TensorFlow, Keras, PyTorch and other libraries have made Python one of the mainstream languages ​​in the field of deep learning and artificial intelligence.
  • Web crawler: Python has powerful web crawling and data extraction libraries, such as BeautifulSoup, Scrapy, etc.
  • Automated operation and maintenance: Ansible, Fabric and other tools use Python to realize automated IT operation and maintenance tasks.
  • Desktop applications: Desktop applications can be created using GUI libraries such as Tkinter and PyQt.
  • Game development: Although not the most common choice, you can also use libraries such as Pygame for simple game development.

3. Write and run the first program

1. Sample code

cmd

Explanation of the first paragraph of decomposed code

hxp_flag = TrueThe meaning of this line of code is as follows:

  • hxp_flag is a variable name. In Python, variables are identifiers used to store data values. You can give the variable any name you want, but there are a few rules to follow: Variable names must start with a letter or an underscore and can be followed by any number of letters, numbers, and underscores. Variable names are case-sensitive, so hxp_flag and Hxp_Flag are different variables. = is the assignment operator.
  • In Python, it is used to assign the value on the right to the variable on the left. In this example, you assign True to the variable hxp_flag.
  • True is a Boolean value in Python that represents true. The Boolean type is one of the basic data types in Python and has two possible values: True and False. Boolean values ​​are often used for conditional judgments and logical operations.

To sum up, the line of code hxp_flag = True means to create a variable named hxp_flag and set its value to Boolean True (True).

The second paragraph of the decomposition code explains

if hxp_flag:
    print('Hello World!')

If the value of hxp_flag is True, the code block within the if statement will be executed and "The value of hxp_flag is True." will be printed. If the value of hxp_flag is False, the code block within the if statement will not be executed. Note: Python's unique "use indentation instead of parentheses to group code blocks" is used here.

interactive mode

The interpreter runs in interactive mode when commands are entered and executed on the terminal (tty). In this mode, a primary prompt is displayed to prompt for the next command. The primary prompt is usually represented by three greater than signs (>>>); when entering consecutive lines, a secondary prompt is displayed. The default is three dots. (...). (>>>), (...) are used in the screenshot of the above code example.

This article is a reprint of the article Heng Xiaopai , and the copyright belongs to the original author. It is recommended to visit the original text. To reprint this article, please contact the original author.

Linus took matters into his own hands to prevent kernel developers from replacing tabs with spaces. His father is one of the few leaders who can write code, his second son is the director of the open source technology department, and his youngest son is a core contributor to open source. Huawei: It took 1 year to convert 5,000 commonly used mobile applications Comprehensive migration to Hongmeng Java is the language most prone to third-party vulnerabilities. Wang Chenglu, the father of Hongmeng: open source Hongmeng is the only architectural innovation in the field of basic software in China. Ma Huateng and Zhou Hongyi shake hands to "remove grudges." Former Microsoft developer: Windows 11 performance is "ridiculously bad " " Although what Laoxiangji is open source is not the code, the reasons behind it are very heartwarming. Meta Llama 3 is officially released. Google announces a large-scale restructuring
{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/u/6851747/blog/11048075