Configuration of the Python development environment for the "Python" version of Windows, Helloworld,python Chinese issues, input and output, conditions, loops, arrays, classes

Source: Internet
Author: User



Python this thing seems to be very useful, but I don't know why it's been so hot.



It is possible that this thing is too difficult to read ~ Read what, send God. Poor English people, the first look at the wrong, but also often misspelled, hehe!



But it's a good thing to say.






First, the configuration of the Python development environment



1, first open the Python's official website https://www.python.org/downloads/download (click Open link) Python development environment. This is the basis of the foundation, equivalent to the JDK in Java status. It is worth noting that python this kid is not honest, and began to change their own grammar to beyond recognition, in the strong push python3.x, but python3.x reputation as jquery2.x very poor, unlike actionscript3.x has more and more supporters. So now python2.x still firmly occupy the major textbooks and the market. Python, of course, knew this, and was afraid to delete the python2.x. Decisive download python2.x.






2, the default is the version of the Windows Python, probably because I am in the win system to browse this page for the sake of. After downloading, it is a direct open. msi. There is nothing to say, always press the next step, the key has two steps to note, in the installation path here by default as shown, if you modify the Python installation path please remember this path, copy to Notepad or whatever is good. For a moment to configure the environment variables.





Another step is that there may be some obsessive-compulsive patients, see Python default is not fully installed as if modified to a full installation. This is not good, because it does not install an item, is to automatically add the system path environment variable. The PATH environment variable is also configured manually. Otherwise, I don't know what's going to happen.






3, install and configure the JDK, Maven, Android ADB, and so on, put the installation path is installed in the system path environment. This thing no longer repeat, specifically can see "Linux" Setting environment variable (click Open link) do a good job directly, directly through the run Open cmd console, enter Python, see version number and help information, while the command line becomes >>> You can now program like a DOS operation for MySQL.



Input:





Print ("HelloWorld")
It is to print a HelloWorld on the console.





Input:





Exit ()
Exit the programming environment. As shown in the following:








This is where Python's basic environment is built. Now you can manipulate the entire operating system by replacing the system's inherent command line with Python in the console. Just like the Linux vim, write C.



Of course, there will be no sense of such a programming environment, anyway, I am.






Second, use Notepad to write Python, with Chinese python program



I think writing python is a bit of a text tool, and then just using the console to run the program. As I write programs with Windows, Linux is a hard-to-use system for running programs. So how do you write Python using Notepad? This is not recommended Python official what idle, pro-Test Chinese garbled into a dog is very troublesome, it is better to use Notepad!



1, first open Notepad, and then enter the following program, it is clear that the first line is why the declaration of this program is Utf-8, you set the default of what Western European language encoding method stand aside!





#-*-coding:utf-8-*-print ("Hello, world!") ")
2, after the preservation, this is clearly the content of primary school information technology ~ The only noteworthy is that the name of the saved file, please bring the suffix name. PY, here is the helloworld.py that is deposited to the F drive. After, the encoding method, please set to ANSI, here do not hand cheap UTF-8, otherwise garbled for a lifetime.








3, then, open the console, enter the F: disk, enter





Python helloworld.py
The "Big program" you write will be executed.











Iii. Python's Ide,python programming basics input and output, conditions, loops, arrays, classes



May see some people here already feel very good, just as some people write PHP with Notepad, in fact this is OK, but now no one in Notepad to write Java, and then use the console Javac compiled after Java execution it? We have to get better at it, using Eclipse's Python Ide,pydey to further improve development efficiency. What the IDE has to do to improve the programming ability is hilarious. I just finished the F, point a alt+/and then fill a return, you are still slowly playing for it, really do not know how to think. Back to the chase.



1, first download Eclipse plug-in Pydey, this thing because of the age, its official website has been a long time not updated, but also flooded with advertising, while the key is the foreign site card into a dog, this thing has been placed in SourceForge place hosted. I am here to give the latest version of Pydev: Http://nchc.dl.sourceforge.net/project/pydev/pydev/PyDev%204.2.0/PyDev%204.2.0.zip (click to open the link), Please use the download tool yourself.



At the same time, this is the Pydev version of the download list:



http://sourceforge.net/projects/pydev/files/pydev/



Seriously not recommended to use the following open Eclipse->help->install New software way to install, here, foreign site source can connect it? Oh! Can be can, Kacheng dog only.






2, after downloading to get a compression bar, directly decompression, close the running eclipse, the file overwrites the Eclipse installation directory things, such as, do not use "Javaweb" Eclipse in the manual installation plugin (click to open the link) way, Because this package is an overwrite of the installation package, Eclipse's manual installation is also not recognized.






3. Open eclipse again may be more than usual to the card, after installation, in the upper right corner of Eclipse, such as open pydev development environment Pydev.






At this point, Eclipse is not able to write Python yet, and you want to configure the Python environment in Eclipse, just like maven. For example, first open window->preferences in the toolbar, then find Pydev->python interpreters Select the Python interpreter, click New Add, the name of the interpreter arbitrary, you do not call Python, called C + + Also, just the place where the python is displayed in the future shows C + + only. The key is the following run path, which is just the python.exe you installed in the Python installation directory. After doing well, the choice of the package, the default is no longer adjust what, all the way to determine.






4. After that, you can finally write python in the Pydev under Eclipse. Later you want to write Java or EE can be used back to the original environment, no problem.



For example, create a new Pydev under the Pydev Project, enter a name, anyway, this is not Java, the class name to the file name corresponding to the package name should be noted everywhere.



Here is the end of the statement without adding a semicolon is just a carriage return on the fixed, for and if do not add {}, a colon to finish the python, very free very short very good scripting language.






5. Create a new Python file under the new Pydev project, such as:






Then write the following one-time instructions for Python input and output, conditions, loops, arrays, classes, annotations using a high level of HelloWorld:



There are so many probabilities, this program can actually write half a book. And then to explain to you what is the concept of input and output, conditions, loops, arrays, classes, for a programmer, this thing has already been memorized in the time of learning C.





#-*-coding: utf-8-*-

# util's sound
class util:
    hello = '你好' #Class member variables
    def sayHello (self, string): # self is a required parameter. Like this in other languages, string is the passed parameter.
        print (self.hello + "," + string); #This is a function that prints a string without a return value
    def max (self, args): # The argument args here is an array, the max function with the return value.
        i = args [0] # first give the first item of the array to i
        for j in args: # This array of variables, the structure of the foreach used here
            if i <j:
                i = j;
        return i;
    
u = util (); # is equivalent to other languages new XX
The function in #raw_input is a prompt message, which is to print a paragraph
name = raw_input ("What's your name?"); #This is python's input. Be sure to use raw_input. Input is problematic.
#The value entered by the user will be assigned to the name variable
u.sayHello (name); #Call u's sayHello method, passing the name of the name just entered by the user
arr = [1,12,3,4,5,6,7,8,9] #Define an array
arrMax = u.max (arr); #Find the maximum value of this array
print "The maximum value of the array arr is:" + str (arrMax);
#The integer that must be returned here must be converted to a string with str () before the overloaded plus sign can be used to connect with other strings. 





The results of the program run as follows:






Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.



Configuration of the Python development environment for the "Python" version of Windows, Helloworld,python Chinese issues, input and output, conditions, loops, arrays, classes


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.