1. python Step 1. python Step 1

Source: Internet
Author: User

1. python Step 1. python Step 1

I have been learning python for some time. I think it's basically an entry point. When I want to write a blog to summarize my knowledge. But I don't know where to start, because the python language is not difficult in syntax. The key is how to build a programmer's way of thinking. For Beginners, it is very difficult to establish this idea, and it is not good to simply stick to various syntaxes. Therefore, my blog mainly shares some of my understandings with you. I cannot guarantee that these understandings are correct. If I find any errors in the future, I will also modify them, it is mainly used for reference and learning, and the syntax is mainly summarized. Therefore, in the syntax section, there will be a lot of references to others' articles, and many things may be repeated with others.

1. Installation Problems:

According to the general procedure, I will introduce how to install python, such as how to install python in windows, how to set environment variables, how to install python in linux, and how to set environment variables. However, there is a saying between programmers: do not duplicate the wheel. When I started learning python, there were already many related tutorials on the internet, and I wrote it again, in addition to time and effort, it is unnecessary to waste server resources. I will not demonstrate it step by step here, so I will summarize the key points.

Windows:

On the windows platform, simply download the installation file from the official website and double-click it to open the installation file. As required, click Next. You can check all the installation items, then you can set the environment variable to use it. You just need to search for the specific steps.

Linux:

It is not difficult to install a linux system, because releases such as centos and ubantu have built-in python, which means they can be directly used without installation. However, when I used centos6.7 for a test, I found that it was built into python2.6 and wanted to replace it with the 2.7 I was learning, when the result is viewed from the yum source, 2.6 is also found in it. In this way, you can only compile and install the source code. The specific compilation method is no longer repeated. After the installation, when you enter the interactive mode again, we find that the version is 2.6. After some tossing, the following solution is obtained.

First, the method for entering the python interaction mode in centos is to directly use the following command. The same should be true for other linux distributions.

[root@localhost ~]# python

 

Here, I strongly recommend that you do not need to have the O & M capability, but at least have some foundation, in the production environment, the server basically uses linux, so our code runs on linux. If we don't understand it at all, it will be difficult to learn it to a certain extent.

Input python here to enter the interpreter because linux knows how to find and run python through environment variables, while in centos, the path of the main python program is/usr/bin/python. However, python2.7 installed in the source code installs all files on/usr/local/python27 by default, if no installation path is set during installation. If the environment variable is not changed, input python and find the original file. Naturally, the newly installed python cannot be run.

At this time, there are several methods:

1. In the future, we will directly use absolute paths to run the python we want, but we generally do not do this because it is too much.

2. Modify the environment variable to point it to the newly installed python. This requires some linux skills.

3. Since we are looking for the original path, we will steal the sky and use a soft connection to link to the new python.

I used the third method. The following shows how to implement it:

Mv/usr/bin/python/usr/bin/python2.6 # rename the original python. You can also delete it. In fact, there is another name called python2.6 in it. Of course, the system version may be different, you can also Rename and overwrite ln-s/usr/local/bin/python/usr/bin/python # To create a soft connection.

 

In this way, when the system looks for the file pointed to by the python system variable, the file found is a soft connection, which is similar to the shortcut in windows, you can find the new python main program. If you do not understand this code, you should learn linux.

However, at this time, our yum tool may become invalid because it is written in 2.6 and may be compatible with the version. At this time, we need to modify the yum execution file, use an older interpreter.

Vim/usr/bin/yum # modify the first line of the file and find the original interpreter #! /Usr/bin/python --> #! /Usr/bin/python2.6

If you have other compatibility issues, you can try this solution.

In this way, the python version is changed. In addition, when you install the python library, you find that the python library is correctly installed, but python cannot be found, most of these libraries are installed in the default path of source code installation by default. However, the Directory of the library that comes with python is not there, and it cannot be found.

2. What can python do?

In many newbie discussion groups, I find that some new users ask this question from time to time. In fact, it doesn't matter what you can do. python is almost omnipotent, But what python is good, crawlers, web pages, big data, and so on all use python. If you want to learn a program as an entry point, python is definitely a good choice.

3. What version of python is better?

This is also a matter of high concern. python is divided into 2. x and 3. there are some differences between the two versions. Many new users are worried that after learning one version, it may take time to learn another version, which is very troublesome.

My personal answer is: if there is no company requirement to use any version, I will learn more about the version, because as a developer, the differences between versions are mostly at the bottom layer, and there are not many differences that can be felt. The following is a summary of 3. some new features of Version x:

1. The default encoding is changed to Unicode. That is to say, you can directly use Chinese without coding declaration;

2. The print keyword is changed to the print () method;

3. raw_input () is changed to input ();

4. The method of class abc: is changed to class abc (object ):;

5. rename some modules;

6. Some changes have taken place in mathematical operations. For example, 1/2 can now correctly produce 0.5, instead of using only integer operations in 2.x. The result is only an integer;

Here is a simple list. For details, refer to the official documentation to learn about the new features of 3.x.

In fact, it can be found that there are not many changes for developers. It is not easy to switch to another version after learning a version completely, so you don't need to worry about the version.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.