current position:Home>Python Basics - (1) overview of Python
Python Basics - (1) overview of Python
2022-06-24 07:50:57【July is your lie】
Python brief introduction
Python The English of is “ boa constrictor ” It means , But its author Guido van Rossum I'm going to call it python The reason is that he is a TV play 《Monty Python's Flying circus》.
The common saying is :python It's a scripting language , But it goes far beyond that ! In addition to being a scripting language , Or a cross platform 、 Open source free Interpretive high-level dynamic programming language , And support object-oriented Programming ideas and methods (python Everything is an object ).
In addition to being able to interpret execution ,python Can also be .py file Pseudo compilation Run as bytecode file , So as to improve the loading and running speed , And encrypt the source code .
To make a long story short ,python It's a door The whole scene Language ! But in terms of usage distribution and characteristics , It is used in numerical calculation 、 Artificial intelligence 、 Script development and other fields are popular .
Python Version selection
(Welcome to Python.org)https://www.python.org/ Python Official website ( Link above ), At the same time provide Python2 . x and Python3 . x Download and install version , But in 2020 year ,python2 The series has stopped the iteration of version update .Python3 And 2 The difference is relatively large , It is embodied in grammar And code Compatibility And portability On .
overall , The higher the version python Its function is also strengthened , Each iteration of the minor version exists as a patch .
The popular advice on the Internet is : choice Python3!
Python Coding standards
Private opinion , Study python The most important thing is the code specification . It pays great attention to the readability of the code , There are grammatical requirements for code layout and typesetting . Let's briefly introduce some python Public norms :
1、python Strictly use code indentation to reflect logical dependencies . Specific for : In each class 、 function 、 Or use a blank line after a complete function code 、 Add a space on both sides of the operator 、 Add a space after the comma separator . In normal assignment statements ,= Add a space to the left and right of the , But when defining the default value parameters of a function and calling a function with key parameters ,= No space is added on both sides !( Such as “def num(age=1): ”age after = There are no spaces on either side of the ).
2、 Every import Language only imports one module , according to “ Standard library “、” Expansion Library “、” Custom library “ Import in the order of . And you don't need to import the entire library , Because this will affect the running speed of the program .
3、 A single python If the sentence is too long , Then use () Branch packing , Or make continuation character : The backslash \. .
4、 To make the code readable , Use parentheses appropriately for complex expressions , And add necessary notes . Single line comment :#, Three quotes ‘’‘ For multiline comments .
5、 At running speed ,python Built-in objects > Standard library >c Language expansion Library > Third party Library . therefore , No special needs , Try to call libraries that run faster .
6、 Among all built-in data types , Try to follow : aggregate 、 Dictionaries > Tuples > list 、 The order of precedence of strings .
Python Import and use of standard library and extended library
pip
In general use pip Tool management expansion Library , Please refer to :
python Of pip command - You know (zhihu.com)https://zhuanlan.zhihu.com/p/68715097
import
import 【 Module name 】as【 Alias 】
After importing in this way , To use related resources, you need to pass the module name . Object :
inport math
math.sin(0.5)
import math as mh
mh.cos(0.5)
from 【 Module name 】 import 【 Object name 】 as【 Alias 】
In this way, only explicitly specified objects are imported , Reduce the number of queries to the library , Improve access speed , Reduce the size of the packed file , It is recommended to use !
from math import sin
sin(5)
from math import sin as s
s(5)
from 【 Module name 】 import *
This is the extreme case of the above usage , All object members in the module can be imported at one time , If not necessary, it is not recommended to use !
from math import *
abs(-3)
The above import methods can import multiple... In turn , It also supports aliasing multiple imported objects .
Python Medium “main” function
_ _name_ _: Module name , Every python When a script runs, it will have a _ _name_ _ attribute , When the execution file is consistent with the current module ,_ _name_ _ The value is equal to the _ _main_ _, This type is a string type . If it is imported as a module , Then the value of this attribute is automatically replaced by the module name
python It is based on script sequence execution , No, main The concept of function , But we can use keywords _ _name_ _ To simulate the .
about _ _name_ _ The command-line parameters of are used in the same way as mian More about , Refer to the following article :
copyright notice
author[July is your lie],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/175/202206240345254236.html
The sidebar is recommended
- Python automatic switching environment
- Detailed explanation of python3 rounding problem
- [Master Wu's Python bakery] day 2
- [Master Wu's Python bakery] day 1
- [Master Wu's Python bakery] day 3
- [Master Wu's Python bakery] day 4
- [Master Wu's Python bakery] day 5
- [Master Wu's Python bakery] day 6
- [Master Wu's Python bakery] day 7
- [Master Wu's Python bakery] day 8
guess what you like
Introduction and examples of socket programming in Python
Python notes - permissionerror
Python notes - deprecationwarning
Python notes - Open Python project
Python notes - PIL Library
Python notes - with as statement
How to export IPython history to Py file?
Python multithreading combined with dataloader to load data
Make Python not echo commands that get password input
In c/c++ and python programming, null and none cannot be distinguished clearly
Random recommended
- Writing sample code for functions in Python
- Summary of operation methods of Python set (about 20 operation methods), with sample code attached
- Python -- functions
- Anonymous and recursive functions in Python
- How to query the methods (member functions) of a class or an object in Python [using the function dir()]
- Summary of operation methods of Python Dictionary (dict) (about 18 operation methods), with sample code attached
- Collect hot search lists in Python at work, which can be called a fishing artifact
- Running Django and Vue on docker
- Data classification in pandas
- About Python: docxtpl is embedded by default when inserting pictures
- How to solve the problem of CSV? (Language Python)
- Installation and use of redis (Python)
- Python implements sending mail (implements single / group mail verification code)
- On the built-in object type of Python -- number (one of the differences between py2 and PY3)
- Python God uses a problem to help you solve the problems of formal and actual parameters in Python functions
- "Project Euler Python Mini tutorial" 001-010 solution introduction
- Most beginners learn Python and web automation. In this way, they learn and give up
- Python matrices and numpy arrays
- Exciting challenge: Python crawler crawls the cover picture of station B
- After installing python3, use the yum command to report an error?
- New features of python3.6, 3.7, 3.8 and 3.9
- Application of Python simplehttpserver
- Python sending mail (single / group) - yagmail module
- After learning these English words, mom doesn't have to worry that I can't learn Python any more
- 1-python+ selenium automated test (detailed tutorial) in the series of exercises of "teach you by hand"
- Cannot unmarshal array into go value of type main
- Analysis of the principle of Python import
- Python quickly saves pictures in wechat official account articles (multiple articles can be specified)
- Python error reporting series (14) -- selenium support for phantom JS has been deprecated
- Python variable data type
- Advanced Python Programming - functions and modules
- Python conditional judgment and loop statements
- Python dictionary nesting
- I want to use Python to write a census management software. I want to ask about the ideas and software involved
- I want to use Python to write a census management software. I want to consult the ideas and software involved.
- Python program has no idea
- How to set the initial position of the cursor in Python Tkinter
- The scrapy framework only gets a set of results. I don't know why (Language Python)
- Code problems in Python
- Python automation framework