Stupid way to learn python (i)

Source: Internet
Author: User
Tags one more line

Exercise 1: First program

You should spend a lot of time in Exercise 0, learn how to install a text editor, run a text editor, and run a command-line terminal, and you've taken the time to familiarize yourself with the tools. Please do not skip the contents of the previous exercise to do the following directly, this is the only one such warning of this book.

1 Print "Hello world!"2 3 Print "Hello Again"4 5 Print "I like typing this."6 7 Print "This was fun ."8 9 Print 'yay! Printing.'Ten  One Print "I ' d much rather you ' not '." A  - Print 'I "said" do not touch this.'
View Code

Write the above content into a file named ex1.py. Note that this naming method is best for Python files ending with. py.

Warning

Do not lose the leftmost number of the above content. These are the so-called "line numbers" where programmers use line numbers when talking about errors in a location in the program. Python also tells you the error message by line number when the program goes wrong, but you don't need to enter these line numbers.

Then you need to run this code at the command line terminal by entering the following:

Python2.exe ex1.py or Python2 ex1.py

Because Python2 and Python3 are installed in my windows, I modified the python.exe for Python2.exe in the Python2 installation directory.

Of course, we can run it completely in cmd (Shift-Right-click, choose to open the Command window here).

If we remove the double quotation marks from the third line, the following is displayed:

This is something you should learn to understand, which is important because you will make similar mistakes in the future. Is that I will make such a mistake now. Let's look at it in one line.

1. First we run the ex1.py script at the command line terminal by entering the command.

2. Python tells us that there is an error in line 3rd of the ex1.py file.

3. The contents of this line are then printed out.

4. Then Python prints a ^ (pound, caret) symbol to indicate where the error occurred. Notice One Less "(double quote, double-quote) symbol?

5. Finally, it prints out a "syntax error (SYNTAXERROR)" To tell you what the error is. Usually these error messages are very difficult to understand, but you can copy the contents of the error message into the search engine, and you can see that others have encountered such errors, and you may be able to find how to solve the problem.

Warning

If you are from another country and you see an error about ASCII encoding, add this line at the top of your Python script: 

# -- Coding:utf-8- -

This allows you to use Unicode UTF-8 encoding in your script, and these errors will not occur.

Bonus points Exercise

You will also have a bonus point exercise to complete. The contents of the bonus exercises are for you to try out. If you think you can't do it, you can skip it for a while and come back for a while.

In this exercise, try these things:

1. Let your script print one more line.

2. Let your script print only one line.

3. Place a ' # ' (Octothorpe) symbol at the beginning of the line. What is the role of it? Do your own research.

From now on, I will not explain how each problem works unless it is a special case.

Note

There are many English names, such as: ' Octothorpe (Bashe) ', ' pound (pound sign) ', ' hash ' (phone's # key) ', ' mesh ', etc.

*************************************************************************************************************** *********************************************

Stupid way to learn python (i)

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.