The Python dictionary has become a widely used computer language, but many people do not know much about the application solutions of the Python dictionary. The following article describes how to use source files in the Python dictionary, you will be rewarded with the introduction of specific application methods.
Use source files
Now let's start programming again. When you learn a new programming language, the first program you write and run is usually a "Hello World" program, which has become a tradition. When you run the "Hello World" program, all it does is say "Hello World ". As Simon Cozens, who proposed the "Hello World" program, said, "It is a traditional spell of the god of programming and can help you better learn languages ."
Start the editor you selected, enter the following program, and save it as helloworld. py. Use source files
- #!/usr/bin/python
- # Filename : helloworld.py
- print 'Hello World'
-
To run this program, open the shellLinux terminal or DOS prompt), and then type the python helloworld. py command. If you are using IDLE, use menu Edit-> Run Script or use keyboard shortcuts Ctrl-F5. The output is as follows. Output
- $ python helloworld.py
- Hello World
If the output you get is the same as the one shown above, congratulations! -- You have successfully run your first Python program. In case you get an error, make sure that the program you typed is correct and then run the program. Note that Python is case sensitive, that is, print is different from Print-note that the first is lower case p and the other is upper case P. In addition, make sure there are no spaces or tabs before the start character of each line-we will discuss why this is important later.
How it works: let's think about the first two lines of the program. They are called annotations-any content on the right of the # symbol is annotated. Annotations are mainly used as notes provided to program readers.
Python should have at least the special form of comments in the first line. It is called an organizational line. The first two characters of the source file are #!, Followed by a program. This line tells your Linux/Unix system which interpreter should be run when you execute your program. This will be explained in detail in the next section. Note: You can always specify the interpreter directly on the command line to run your program on any platform. Just like the python helloworld. py command.
Rational use of comments in your program to explain some important details-this will help readers of your program easily understand what the program is doing. Remember, this reader may be you six months later!
After the annotation, a Python statement is used to print the text "Hello World ". Print is actually an operator, and "Hello World" is called a string-don't worry, we will explain these terms in detail later.