In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "Python basic knowledge Point Analysis". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Python introduces the history of Python
Christmas 1989: Guido von Rossum starts writing compilers for the Python language.
February 1991: the first Python compiler (also an interpreter) was born, which was implemented in C (followed by Java and C # implementation versions Jython and IronPython, as well as PyPy, Brython, Pyston, and other implementations), which can call C language library functions. In the earliest versions, Python has provided support for building blocks such as "classes", "functions" and "exception handling", as well as core data types such as "lists" and "dictionaries", as well as module-based extension systems.
January 1994: Python 1.0 is officially released.
October 16, 2000: Python 2.0 was released, adding full garbage collection and support for Unicode. At the same time, the whole development process of Python is more transparent, the influence of the community on the development progress is gradually expanding, and the ecosystem begins to form slowly.
December 3, 2008: Python 3.0 was released, which is not fully compatible with the previous Python code, but because there are still many companies using Python 2.x in projects and operations, many new features of Python 3.x were later migrated to Python 2.6 and 2.7.
The version of Python 3.7.x we currently use was released in 2018, and the version number of Python is divided into three segments, such as A.B.C. Where A represents a large version number, generally, when the whole is rewritten, or when there is a change that is not compatible backward, the addition of A position B indicates a function update, and when a new function appears, it means a small change (such as fixing a certain Bug), and whenever there is a change, add C. If you are interested in the history of Python, check out a blog post called "A brief History of Python".
Advantages and disadvantages of Python
There are many advantages of Python, which can be summarized as follows.
Simple and clear, there is only one way to do something.
The learning curve is low, and Python is easier to use than many other languages.
Open source code, with a strong community and ecosystem.
Interpretive language is inherently platform portable.
Support for two mainstream programming paradigms (object-oriented programming and functional programming) is supported.
For extensibility and embeddability, you can call either the code or the Python in the CumberCure + code.
The code is highly standardized and readable, so it is suitable for people with code cleanliness and obsessive-compulsive disorder.
The disadvantages of Python mainly focus on the following points.
Execution is slightly less efficient, so computationally intensive tasks can be written by Cramble +.
The code cannot be encrypted, but many companies now sell services instead of software, and this problem will be watered down.
There are too many frameworks to choose from during development (for example, there are more than 100 Web frameworks), and where there is a choice, there are mistakes.
The application field of Python
At present, Python is widely used in cloud infrastructure, DevOps, web crawler development, data analysis mining, machine learning and other fields, so it has also created a series of positions such as Web back-end development, data interface development, automatic operation and maintenance, automatic testing, scientific computing and visualization, data analysis, quantitative trading, robot development, image recognition and processing.
Build programming environment Windows environment
You can download Python's Windows installer (exe file) from Python's official website. It is important to note that if you install in Windows 7, you need to install the Service Pack 1 patch pack first (you can install it through the automatic installation of system patches by some tool software). During the installation process, it is recommended to check "Add Python 3.6 to PATH" (add Python 3.6 to the PATH environment variable) and select custom installation. In the setting "Optional Features" interface, it is best to check "pip", "tcl/tk", "Python test suite" and other items. It is strongly recommended to use a custom installation path and ensure that there is no Chinese in the path. When the installation is complete, you will see the prompt for "Setup was successful", but when you start the Python environment, the Python interpreter may not run because some dynamic link library files are missing. The common problems are the missing api-ms-win-crt*.dll and the missing dynamic link library files caused by updating DirectX. The former can be repaired by referring to the article "api-ms-win-crt*.dll missing cause Analysis and Solutions" or download Visual C++ Redistributable for Visual Studio 2015 file directly from Microsoft's official website, while the latter can download a DirectX repair tool for repair.
Linux environment
The Linux environment comes with version 2.x of Python, but if you want to update to version 3.x, you can download the source code of Python from the official website of Python and install it by building the source code, as shown below.
Install dependent libraries (because the absence of these dependent libraries may fail because the underlying dependent libraries are missing when the source code artifacts are installed).
Yum-y install wget gcc zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
Download the Python source code and extract it to the specified directory.
Wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgzxz-d Python-3.7.3.tar.xztar-xvf Python-3.7.3.tar
Change to the Python source directory and execute the following command to configure and install.
Cd Python-3.7.3./configure-prefix=/usr/local/python37-enable-optimizationsmake & & make install
Modify the file named .bash _ profile in the user's home directory and configure the PATH environment variable to take effect.
Cd ~ vim .bash _ profile#... The above code is omitted here. Export PATH=$PATH:/usr/local/python37/bin#. The following code is omitted here. Source .bash _ profileMacOS environment
MacOS also comes with version 2.x of Python, and version 3.x can be installed through the installation file (pkg file) provided on Python's official website. After the default installation is complete, you can start the 2.x version of the Python interpreter by executing the python command on the terminal, and the 3.x version of the Python interpreter by executing the python3 command.
Run the Python program from the terminal to confirm the version of Python
Type the following command at the terminal or command line prompt.
Python-version
Of course, you can enter python to enter the interactive environment, and then execute the following code to check the version of Python.
Import sysprint (sys.version_info) print (sys.version) write Python source code
You can use text editing tools (advanced text editing tools such as Sublime, Atom, TextMate, VSCode, etc.) to write Python source code and save it as hello.py, as shown below.
Print ('hello, Worldwide') Run the program
Change to the directory where the source code is located and execute the following command to see if "hello, world!" is printed on the screen.
Comments in python hello.py code
Comments are an important part of the programming language, which is used to explain the role 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 running through comments. This is often used when debugging programs. Comments are removed when entering the preprocessor or compilation with the source code, and are not retained in the target code or affect the execution results of the program.
Single-line comments-parts that begin with # and spaces
Multiline comments-start with three quotes and end with three quotation marks
The first Python program-hello, world! pays tribute to the great Mr. Dennis M. Ritchie Version: 0.1Author: Luo Hao "print ('hello, Worldwide') # print (" Hello, World! ") Print ('Hello', 'World') print ('hello',' world', sep=',', endgame developers') print ('goodbye, world', endgame tools!\ n') other tools introduce IDLE-an integrated development tool that comes with it
IDLE is an integrated development tool that comes with installing the Python environment, as shown in the following figure. However, because the user experience of IDLE is not so good, it is rarely adopted in actual development.
IPython-A better interactive programming tool
IPython is an interactive interpreter based on Python. Compared to the native Python Shell,IPython, it provides more powerful editing and interactive capabilities. You can install IPython and Jupyter through Python's package management tool, pip, as shown below.
Pip install ipython jupyter
Or
Python-m pip install ipython jupyter
After the installation is successful, you can start IPython with the following ipython command, as shown in the following figure.
Of course, we can also run a project named notebook through Jupyter to operate interactively in the browser window.
Jupyter notebook
Anaconda-an one-stop data science artifact
Anaconda refers to an open source Python distribution that contains more than 180 science packages such as conda and Python and their dependencies. Because it contains a large number of science packages, the download file of Anaconda is relatively large (about 531 MB). If you only need some packages, or if you need to save bandwidth or storage space, you can also use Miniconda, a smaller distribution (including only conda and Python). For those who study data science, anaconda is an absolute artifact, easy to install, and anaconda supports the installation of related software (such as ipython,jupyter notebook mentioned earlier, and even other data science software such as R) A valuable introduction now the only problem is that Tsinghua mirror service has been turned off, cross-border downloads will be slow.
Sublime-text editing artifact
You can first download the installer and install Sublime 3 or Sublime 2 from the official website.
Install package management tools.
Import urllib.request,os;pf='Package Control.sublime-package';ipp=sublime.installed_packages_path (); urllib.request.install_opener (urllib.request.build_opener (urllib.request.ProxyHandler (); open (os.path.join (ipp,pf), 'wb') .write (urllib.request.urlopen (' http://sublime.wbond.net/'+pf.replace('','% 20')) .read () import urllib2,os;pf='Package Control.sublime-package' Ipp=sublime.installed_packages_path (); os.makedirs (ipp) ifnotos.path.exists (ipp) elseNone;urllib2.install_opener (urllib2.build_opener (urllib2.ProxyHandler (); open (os.path.join (ipp,pf), 'wb') .write (urllib2.urlopen (' http://sublime.wbond.net/'+pf.replace('','% 20'). Read ()); print ('Please restart Sublime Text to finish installation')
Sublime 2
Sublime 3
After manually installing the browser and typing https://sublime.wbond.net/Package%20Control.sublime-package to download the file, open sublime text and select the menu Preferences- > Browse Packages... When you open the installation directory, you will go to a directory called Packages, and click to enter the upper directory Sublime Text3, where there is a folder called Installed Packages. Just put the files you just downloaded here. Then restart sublime text3 to see if there are two options, Package Settings and Package Control, at the bottom of the Preferences menu. If so, the installation is successful.
Use the shortcut key Ctrl+ `or select Show Console from the View menu to open the console and enter the following code.
Install the plug-in. Open the command panel through the Package Control of the Preference menu or the shortcut key Ctrl+Shift+P, and type Install Package in the panel to find the tool to install the plug-in, and then find the plug-in you need. We recommend installing the following plug-ins:
SublimeCodeIntel-Code completion tool plug-in.
Emmet-the front end develops the code template plug-in.
Git-version control tool plug-in.
The Python PEP8 Autoformat-PEP8 specification automatically formats plug-ins.
ConvertToUTF8-converts the local encoding to UTF-8.
PyCharm-Python development artifact
The installation, configuration, and use of PyCharm will be described later.
Gitpod-one-button online development tool
You can open any Python project on GitHub with a single click.
Practice
View the following code result in the Python interactive environment and translate the content into Chinese.
Import thisBeautiful is better than ugly.Explicit is better than implicit.Simple is better than complex.Complex is better than complicated.Flat is better than nested.Sparse is better than dense.Readability counts.Special cases aren't special enough to break the rules.Although practicality beats purity.Errors should never pass silently.Unless explicitly silenced.In the face of ambiguity Refuse the temptation to guess.There should be one-- and preferably only one-- obvious way to do it.Although that way may not be obvious at first unless you're Dutch.Now is better than never.Although never is often better than * right* now.If the implementation is hard to explain, it's a bad idea.If the implementation is easy to explain, it may be a good idea.Namespaces are one honking great idea-let's do more of those!
Learn to use turtle to draw graphics on the screen.
Import turtleturtle.pensize (4) turtle.pencolor ('red') turtle.forward (100) turtle.right (90) turtle.forward (90) turtle.right (90) turtle.forward (90) turtle.right (90) turtle.forward (100) turtle.mainloop () "Python basic knowledge Point Analysis" is here. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.