current position:Home>Notes on python (I): getting to know Python

Notes on python (I): getting to know Python

2022-01-30 10:44:05 A bowl week

Little knowledge , Great challenge ! This article is participating in “ A programmer must have a little knowledge ” Creative activities .

Hello everyone , I am a A bowl week , One doesn't want to be drunk ( Internal volume ) The front end of the . If you are lucky enough to get your favor , I'm very lucky ~

Python brief introduction

Python The history of

  1. 1989 Christmas :Guido von Rossum Start writing Python Compiler of language .
  2. 1991 year 2 month : first Python compiler ( It's also an interpreter ) Be born , It is to use C The realization of language ( Back ), You can call C Library functions of a language . In the earliest version ,Python Has been provided for “ class ”,“ function ”,“ exception handling ” And so on , And the list 、 Dictionary and other core data types , At the same time, it supports building applications based on modules .
  3. 1994 year 1 month :Python 1.0 Official release .
  4. 2000 year 10 month 16 Japan :Python 2.0 Release , Added full Garbage collection , Provide for the right to Unicode Support for . meanwhile ,Python The whole development process is more transparent , The impact of the community on the development schedule is growing , The ecosystem began to take shape .
  5. 2008 year 12 month 3 Japan :Python 3.0 Release , It is not fully compatible with previous Python Code , But at present, there are many companies using it in projects and operation and maintenance Python 2.x edition , therefore Python 3.x Many of the new features were later ported to Python 2.6/2.7 In the version .

Currently we use Python 3.7.x The version of 2018 Published in ,Python Version number of is divided into three sections , Form like A.B.C. among A Indicates large version number , Generally when the whole is rewritten , Or when there is a change that is not backward compatible , increase A;B Indicates function update , Add when new features appear B;C Represents a small change ( for example : Fixed a Bug), Add as long as there are changes C. If the Python Interested in the history of , You can read the 《Python Brief history 》 Internet articles .

Python Advantages and disadvantages

Python Many advantages , It can be summarized as follows .

  1. Simple and clear , Low learning curve , Easier to use than many programming languages .
  2. Open source , With a strong community and ecosystem , Especially in the field of data analysis and machine learning .
  3. Explanatory language , Born with platform portability , Code can work on different operating systems .
  4. Two mainstream programming paradigms ( Object oriented programming and functional programming ) All supported .
  5. High level of code specification , High readability , It's suitable for people with code cleanliness and obsessive-compulsive disorder .

Python The main shortcomings of this paper are as follows .

  1. Less efficient execution , The parts requiring high execution efficiency can be written in other languages ( Such as :C、C++) To write .
  2. The code can't be encrypted , But now many companies do not sell software but services , This problem will be weakened .
  3. At development time There are too many frames to choose from ( Such as Web The framework has 100 Multiple ), Where there is a choice, there is a mistake .

Python Application fields of

at present Python stay Web Application backend development 、 Cloud infrastructure construction 、DevOps、 Network data collection ( Reptiles )、 automated testing 、 Data analysis 、 Machine learning and other fields have a wide range of applications .

install Python Interpreter

install Python The interpreter is relatively simple , There's no demo here

function Python Program

testing Python Is the installation complete

stay Windows In the command line of the, type the following command :

python --version
# Python 3.10.0
 Copy code 

Of course, you can type python or python3 Enter the interactive environment , Then perform the following code check Python Version of .

python
# Python 3.10.0 (tags/v3.10.0:b494f59, Oct  4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)] on win32
# Type "help", "copyright", "credits" or "license" for more information.
# >>> import sys
# >>> print(sys.version)
# 3.10.0 (tags/v3.10.0:b494f59, Oct  4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)]
# >>> exit()
 Copy code 

To write Python Source code

You can use text editing tools ( Recommended SublimeVisual Studio Code And other advanced text editing tools ) To write Python Source code and py Save the file as a suffix , The code content is as follows :

print('hello, world!')
 Copy code 

Run the program

Switch to the directory where the source code is located and execute the following command , See if there is any output on the screen "hello, world!".

python hello.py
 Copy code 

or

python3 hello.py
 Copy code 

notes

Annotation is an important part of programming language , It is used to interpret the function of the code in the source code to enhance the readability and maintainability of the program , Of course, you can also remove the code segments in the source code that do not need to participate in the operation through comments , This is often used when debugging programs . Comments are removed when they come into preprocessor or compilation with source code , It will not remain in the target code and will not affect the execution result of the program .

  1. Single-line comments : With # And the beginning of the space
  2. Multiline comment : Three quotes at the beginning , Three quotes end
#  Print  hello world
print('Hello World')

'''
 This is a multiline comment 
'''
 Copy code 

copyright notice
author[A bowl week],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/01/202201301044039059.html

Random recommended