Python Day 1 --- first Python program, python ---

Source: Internet
Author: User

Python Day 1 --- first Python program, python ---

 

1. If my environment is windows, you need to install notepad ++, install Python2, and configure the environment variables (For details, refer to below)

2. Open the cmd window -----Input I:[Enter the disk on which the python code is to be stored (my code on I: \ pyhtonCode )]

------Enter cd PythonCode to enter the PythonCode folder]

 

3. Open the I: \ pyhtonCode folder and create a txt file namedFirst. py, right-click it and open it with nodepad ++

4. Open the document and enter the following code:

1 #! /Usr/bin/python 2 # coding: UTF-8 3 print "Hello world" 4 print "Hello Fei" 5 print "I like apple" 6 print 'Juan '7 8 # Exercise 1 -- print a row more 9 print "I am exercise 1 "10 11 # Exercise 2 -- print only one row 12 # comment out others, leave only one row

5. In cmd, enterPython first. py

6. Display

Common Errors:

(1)

If this is displayed, you may have run python and then run python again in the python environment. Close and restart the command line.
In cmd, just type python first. py. Like this:

 

(2) The man or other languages written in the Code cannot be output and displayed.

It indicates the encoding problem. In python, the default encoding format is ASCII, so Chinese characters cannot be correctly printed without modifying the encoding format.

Solution: In every python file that needs to display Chinese characters in the future, you can use the following method in #! Add a sentence to the next line of/usr/bin/python to define the encoding format. I will use UTF-8 encoding as an example.

First:

1 #! /Usr/bin/python2 # coding: utf-83 print "how are you"

Second:

1 #! /Usr/bin/python2 #-*-coding: UTF-8-*-3 print "how are you"

Third:

1 #! /Usr/bin/python2 # vim: set fileencoding: utf-83 print "hello"

* ** Note: this line of code defining the encoding format must be placed in the first or second line. Generally, if the first line is the code that prompts the python location, the line defining the encoding format must be placed in the second line. Otherwise, an error will still be prompted.

 

 

 

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.