Learning Python also has a period of time, since the basic is considered to be a beginner, want to write some blog to summarize the knowledge of the time. But found do not know where to start, because the Python language in fact is not difficult, the key lies in how to build the programmer's way of thinking, and for beginners programming people, it is very difficult to build this idea, simple hard back all kinds of grammatical effect is not good. So my blog is mainly to share some of their own understanding of the people, and these understanding I can not guarantee that it must be correct, if the late found that there is something wrong, I will also make changes, mainly for reference learning, and for the grammar is mainly summed up, so in the grammar section will be a lot of reference to others articles, There may be a lot of things to repeat with others.
1. Installation issues:
According to the routine, I should describe how to install Python, such as how to install under Windows, how to set environment variables, how to install Linux, how to set environment variables and so on. However, the programmer has a sentence: Do not create repetitive wheels, when I began to learn python, the network has a lot of relevant tutorials, and I write again, in addition to time and effort to waste server resources, there is no need. I'm not here to demonstrate, just a little summary of the main points.
Windows system:
Windows platform directly to the official website to download the installation files, and then double-click to open the installation files, according to the requirements of the next step is almost, in the choice to install what things, all hook can also, and then set the environment variables, you can use, specific steps to search for a bit, here no more say.
Linux systems:
The installation of Linux systems is hard to say, as distributions such as CentOS and Ubantu are actually built into python, which means that they can be used directly without installation. But I encountered such a situation, I used centos6.7 to do the test, I found that it is built in the python2.6 version, but also want to replace it with the 2.7 I am learning, the results to the Yum source to see, found inside is also 2.6. This can only be compiled by their own source code installation, how to compile and no longer repeat, after installation again into the interactive mode, the discovery version is still 2.6. After a toss-up, the following solution was obtained.
First, the way we enter Python interactive mode in CentOS is to use the following commands directly, as should other Linux distributions.
[[email protected] ~]# python
Here, I strongly recommend that you need to learn Linux system, do not require to have the ability to do operations, but at least have some foundation, because in the production environment of the basic Linux server, so that our code is running on Linux, if not understand at all, after learning to a certain extent will be difficult.
This is where Python enters the interpreter because Linux knows how to find Python and run it through environment variables, and in CentOS, the path to the main program of the Python is /usr/bin/python , However, our source-installed python2.7 will install all files by default in /usr/local/python27 if the installation path is not set at the time of installation. Environment variables do not change, then input python , looking for the original file, will not be able to run our newly installed Python.
At this time, there are several methods:
1. We will use the absolute path in the future to run the python we want, but generally we do not, because it is too 2.
2. Modify the environment variables to point to our newly installed Python. This requires a certain amount of Linux skills.
3. Since we are looking for the original path, let's take a bogus and link to the new Python with a soft link.
I used the third method, and here's how it's implemented:
MV /usr/bin/python/usr/bin/python2. 6 #重命名原来的python, can also be deleted, in fact, there is also a call python2.6, of course, may vary depending on the system version, renaming overrides can also ln -s/usr/local/bin/ Python/usr/bin/python #建立一个软连接
In this way, when the system goes to find Python this system variable pointing to the file is, and the file found at this time is a soft connection, this is a similar to the shortcut in Windows things, all can continue to find the newly installed Python main program. If you do not understand this code, or that sentence, it is time to learn to learn Linux.
However, our Yum tool may fail at this point because it is written in 2.6 and there may be version compatibility issues, at which point we will modify the Yum execution file to use the old version of the interpreter.
vim/usr/bin/Yum#修改文件的第一行 to find the original interpreter #!/usr/bin/python--and #!/usr/bin/python2. 6
If you also go to other versions of compatibility issues, you can also try this workaround.
In this way, the Python version of the replacement is complete, in addition, how to install the Python library later, when you find that obviously installed correctly, and Python can not find, most likely these libraries are installed by default to the source code installation default path. The repository of the Python library is not there, and it's not going to be found.
What 2.python can do
I am in a lot of novice communication group will find every now and then a novice ask this question, actually does not matter what can do, Python is almost omnipotent, but lies in what Python is good at doing, crawlers, Web pages, big data, etc., are used in Python, if you want to learn a program as an introduction, Then Python is definitely a good choice.
3. Learn what version of Python is good
This is also a matter of great concern, Python is divided into 2.x and 3.x versions, and there are some differences between the two versions, many novice worried that after learning one version, it may take time to learn another version, which is cumbersome.
And my personal answer is, if there is no company required to use what version, then what version of the information to learn more that, because in fact, as a developer, the difference between the version is more on the bottom, can feel the difference is not much, the following summarizes the 3.x version of some of the new features:
1. The default encoding is changed to Unicode, that is, you can use Chinese directly without coding declaration;
2.print keyword changed to print () method;
3.raw_input () changed to input ();
4.class ABC: The wording changed to class ABC (object):;
5. renamed some modules;
6. Mathematical operations have undergone some changes, such as 1/2 can now be correctly obtained 0.5, instead of the 2.x only with integer arithmetic, the result is only the integer digits;
Here's a quick list of what you can see in the official documentation to learn about the new features of 3.x.
In fact, it can be found that for developers, not many changes, after fully learning a version, then switch to another version is simply not too easy, so do not care about the version of the problem.
The first step of 1.python