If you like WeaponZhi’s article, you can keep track of what’s going on on our public account WeaponZhi
This is part 1 of “The Road to AI Learning” and part 1 of “Learning Python.
preface
1. Organization of Python chapters
Whether it is learning artificial intelligence or big data, Python is a basic must to learn, and if you have a certain language foundation, you will find Python is very easy to get started. I spent about one afternoon to get started on basic syntax.
I’ll give you a basic introduction in three or four chapters. Of course, this does not mean that our knowledge of Python is enough to learn about ARTIFICIAL intelligence or big data, nor does it mean that I will only write a few Python articles in the course of the entire SERIES on artificial intelligence. Instead, I put a lot of emphasis on learning Python itself, and I share a lot of original Python-related content.
The more proficient I am in Python, the more helpful IT will be for me to learn popular technologies such as artificial intelligence or big data in the future. Moreover, Python can be used to solve many scenarios in my work, which greatly improves my work efficiency, even though the main language in my work is not Python. You’ll see this as you learn Python.
So, the Python articles will be interspersed with other articles. Today I will publish an algorithmic article, and tomorrow I will publish a Python article. My promise is that all articles will be organized and consistent, so that even readers who follow later will be able to learn them step by step.
2. How to learn Python autonomously
There are a lot of resources on the Web these days, and Python materials are coming out all the time. There are two recommended ways to get started with Python:
The first one is to recommend you to have a look at ** “Liao Xuefeng’s Python tutorial” **, highly recommended, I just watched his tutorial in the afternoon to learn.
The second is co* decademy, which has dozens of language how-to tutorials. It’s a how-to approach that can be documented, compiled and run online, and can be hand-held. It’s a little embarrassing that most of the tutorials are in English, but thankfully the tutorial itself isn’t complicated enough to make sense of. The interface looks like this:
Of course, it’s perfectly possible to get started by reading my article.
Again, it’s not just about being in Python. You can buy more books, read more blogs, write more. Of course, I’ll also be sharing advanced techniques in Python. The most important thing is persistence. Many people are similar to me. Python is not the main language for work or learning, and they need to learn it in their spare time, which tests one’s willpower.
It’s okay. At least I get to jerk off with you.
Introduction of Python
1. Advantages of Python
Python is a very high-level language, and C and Java may require many times or even dozens of times more code to implement the same logic as Python. Python is simple and elegant. Try to write as little code as you can easily read.
We can compare this difference between Java and C. C language, at the time of construction of entity object, need to use the code manually to open up space in memory, and then gives good this up space to use an object, use up, still have to manually go to release this part of the space, benefits to memory or some of the hardware of the control force is very strong, and force the programmer to the strict regulation of the use of these resources, But needless to say, it was too much trouble, and I had to write so much non-business code just to write a business logic.
The JVM’s garbage collection mechanism does this for you by automatically marking which memory space is recyclable through methods such as reachability algorithms, and then collecting memory without your code doing anything about it. Of course, the disadvantages are obvious. You don’t really know what the garbage collection mechanism does, it’s not very scalable and controllable, and if you need to pay special attention to the recycling, it can be very troublesome and uncontrollable.
Python also has a lot less to worry about than Java, such as asynchrony, which is a lot more difficult for Java to handle. Python can cover almost every application you can think of because it provides a very complete base of code, and the wheels are very complete.
It is worth mentioning that Python has developed rapidly in recent years. It can support and apply the most cutting-edge and popular technologies such as artificial intelligence and big data well. Python has overtaken Java for the first time in GitHub’s 2017 development language activity ranking, jumping to second place behind JS.
2. Disadvantages of Python
There are gains and losses, and Python is not perfect. Liao da summed up very well, I briefly overview.
First of all, Python is slow because Python is an interpreted language. As Python code runs, it is translated line by line into machine code that the computer can understand. As you can imagine, this process is slow. C, on the other hand, compiles the code to machine code before it runs, which makes execution extremely fast.
But in fact, this speed gap is not unacceptable, Liao Dada also made a very interesting analogy in his article, here quoted, we experience the impact of this speed gap:
A lot of applications don’t need to run that fast because users don’t feel it. For example, to develop a web application for downloading MP3, the C application takes 0.001 seconds to run, while the Python application takes 0.1 seconds. This is 100 times slower, but because the network is slower, the wait time is 1 second. Do you think the user will feel the difference between 1.001 seconds and 1.1 seconds? This is just like the formula One car and the ordinary taxi driving on the Third Ring Road in Beijing, although the FORMULA One car theoretical speed of 400 kilometers per hour, but because of the third ring road traffic only 20 kilometers per hour, so, as a passenger, you will always feel 20 kilometers per hour.
Another drawback is that Python cannot be encrypted. If your application is written in Python, you are exposing your source code when you publish it. However, in the Internet era, the business model to survive by selling software is less and less, more rely on services and websites, not only that, in this era of open source spirit, source code itself is not very terrible, do not overestimate the value of their own code.
Python running requires an editor to translate Python code into code that a particular operating system can understand. Unlike Java, any device that can run a Java virtual machine can run Java applications.
Install Python
OK, let’s do one thing instead of ten words, so let’s start installing Python.
Python 3.x and 2.x are incompatible, so we, as beginners, will go straight to 3.x without worrying about history. Here I will not spend the space to introduce the installation process, there are many online tutorials, need to pay attention to the main Windows partners must remember to configure environment variables.
Python files require an interpreter to execute. With Python installed, we actually have an official interpreter: CPython, which is the most widely used Python interpreter. There are many other interpreters. PyPy, for example, is faster than CPython; Jython and IronPython are interpreters on other platforms that can compile Python code into Java or.NET bytecode.
When all is ready, type Python on the Windows console and press Enter, or python3 on a Mac or Linux terminal. If this screen appears, your installation is successful!
As usual, do we have to say Hello world? Enter the code after >>>!
>>> print ('hello, world')
hello, world
Copy the code
Welcome to follow my public number
I want to be friends with you