Python Getting Started tutorial (0)

Source: Internet
Author: User

(This article is for Windows)

What is Python? is a programming language. What is a programming language? Is the way you talk to machines. Compilers and interpreters are like translators, turning your words into machines that understand them. But these translations are not as intelligent (though they are), and you have to say a very mechanical bureaucratic that they can help you translate-but it's much easier than talking to the machine directly.

(But you can only let the machine do what it can do, right?) You can't let the CPU dance. )

Communication is awkward. You don't know what the machine is capable of, but the machine waits for you to tell him what to do--like a stranger on a train. So you knocked on his shoulder and asked, "Do you know about artificial intelligence?" (laughter)--you ask the CPU: Can you show some words on the screen? The CPU won't answer you, but I'll tell you: Yes, you just type print ("..."), write what you want to show in the ellipsis, and then hand it over to a translator called Python, which translates the words into a machine-readable scribblings. Then you take the scribblings to find the machine and say: "Do it!" "The machine is moving (although the CPU is still in the chassis and is not moving). Fortunately the display changes can be seen, you can know that the CPU did something.

You know that Python can be downloaded online, and then downloaded and installed by default. But then you don't have a mind: "Where can I find the translation of Python?" How do I tell him that print ("Do you know AI?")? "But maybe you're smart enough to find Python from the list of programs, and then excitedly enter print (" Do you know AI? "), hit Enter to enter, and find that there's more than one line that you want it to show.

You changed the quotation marks and tried it a few times, quite proud of it. In fact, you may find that this machine is not inhuman, such as

You can even lose a long formula, and the result will come. But if you want to use "^" to calculate the powers, the machine shows something weird. Although I can tell you that two asterisks in Python are powers, but come back to God , programming is not exactly a conversation with a machine, and in many cases it is a matter of telling him a bunch instead of a sentence. For example, what if you want him to count as prime number within 100? You may think of what I said before--

...... Give this to a translator called Python, translation will translate this into a machine to understand the scribblings. Then you take the scribblings to find the machine and say: "Do it!" "The machine is moving ...

You just didn't do it! So, who did you see? In fact, the window just now called "Interactive interpreter", plainly speaking is the dialog box. But we often use the "interpreter", which is generally non-interactive. Although the dialog is also an interpreter, this is a companion feature, and the "right" approach is:

1. open a notepad and write the code into it (such as the One in print ("...") and change the suffix to. py instead of. txt on save.

    1. Hand it to Python. In fact most of the language will give you scribblings, but Python just throw scribblings to the machine, you finally don't know what scribblings look like (but also some). When you hand it over to Python, Python translates it directly to the machine and executes the one-stop service. The way to Python is this: hold down SHIFT right in the directory where the code files are, and click "Open Command Window Here"(Eh, dialog box?). ), tap Python xxx.py (and enter), then Python will translate and the machine starts executing.

Here to explain the "command Window", called the Command line (of course can also ignore the awkward call it command prompt), is you and the computer dialogue place. This is the computer's own translation, you just do the things you can do (you enter echo Hello cmd to try?) )。 But the code can do complex things, do a lot of things at once (like counting 100 primes), which is what the command line and the interactive interpreter can't do. In fact, the command line can also write code, but where to run it? You have to open the command line. So anyway, running is the command line playing Python xxx.py.

Paste the following code in your notepad and try running it: (you can press CTRL + C to do something)

def space(a):    pencil=""    for x in range(1,a+1):        pencil=pencil+" "    return pencildef pen(a):    pen_a=space(a%20)+"*"+space(38-2*(a%20))+"*"+space(a%20)    return pen_ax = 0while True:    x += 1    print(pen(x-1))

(In fact, these can be double-click to run, but double-click Run is not a good habit, imagine the year without a mouse and graphical interface to do?) In addition, the command line code--bat file and cmd file, you may have heard that the suffix is different but the content is consistent, are conditional loops and so on. However, the reason for using Python is because of the difference in the upper layer ... )

(In fact, Python xxx.py can be omitted as xxx.py, because many suffix names will let the machine know what you are going to do, such as seeing. PY is the default you need to find the translator of Python to deal with.) But just omitted, Notepad xxx.py is to let Notepad to handle, try? )

Python Getting Started tutorial (0)

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.