Python getting started tutorial (2), python getting started tutorial
My life is so short that I play with snakes 0.0!
Python is an object-oriented, interpreted computer programming language, invented by Guido van rosum at the end of 1989, the first Public release was released on July 15, 1991. The Python source code also complies with the GPL (GNU General Public License) protocol. The Python syntax is concise and clear, and has rich and powerful class libraries. It is often called the glue language, and can easily connect various modules (especially C/C ++) made in other languages. A common application scenario is to use Python to quickly generate a prototype of a program (sometimes even the final interface of the Program) and then have a special requirement on it, rewrite with a more appropriate language. For example, if the graphic rendering module in 3D games has high performance requirements, you can rewrite it with C/C ++ and encapsulate it as an extension class library that can be called by Python. Note that you may need to consider Platform issues when using the extended class library, and some may not provide cross-platform implementation.
Chapter 1 Introduction to Python
Preface
PythonIt may be a rare simple and powerful programming language that can be called. It is a brand new experience for beginners and experts. More importantly, it is a pleasure to use it for programming. This book will take you on a new fantastic programming journey (there will be eggs in the book !) -- In essence, "bringing joy to your programming! Provide a perfect solution for your programming ".
That is, the Python human-door programming (1) in the previous chapter. Let's continue with the editor required for getting started with Python.
1. Python program execution Method
1. Linux Users enter the Python command to start the interpreter at a shell prompt.
2. For Windows users, if the PATH variable has been configured, you can start the interpreter in the command line.
3. If you use IDLE, click(Python GUI ).
Note: Python will output the output immediately in the next line. You can press Ctrl + N to edit all your code with Untitled, and then run your results in Shell! Here, we use the text Hello World, which is quickly printed on the screen.
2. Select a common Python editor.
Before writing program source files in Python, an editor is required. It is really important to select an editor. programmers who want to learn C/C ++ can select PyCharm, PyScripter, and LDLE (Python GUI, it is recommended that programmers use the first two editors. Java programmers can select the eclipse add function PyDev to edit Python (the tutorial can be viewed on the official website tomorrow), ASP.. NET development programmers can use the Python Application added to Visual Studio 2015 to edit Python (the tutorial can be viewed on the official website tomorrow), so that you are familiar with your operating environment, you can also learn your favorite Python.
2.1 LDLE (Python GUI) Editor (beginner)
If you are using Windows, we recommend that you use IDLE. IDLE has syntax highlighting, and different parts have different colors, so that you can see your program to make it more vivid. For example, if you run your program in IDLE, note that you should not use Notepad-it is a bad choice because it does not have the syntax brightening function, more importantly, it does not support text indentation.
This book uses two editors to demonstrate the Python running process. IDLE is installed by default in the Python installer in Windows.
Now return to the program. There is a convention that when learning a language, the first program is to write and run the 'hello world' program-to output "Hello World" when running the program ". Just like "it is a traditional spell of the god of programming, it can help you better learn the language :":)
Open the shell (Linux terminal or doscommand prompt) and type Python helloworld. py to run the program.
For IDLE, press enter to run the program. In the IDLE editor, you can press F5 to run the program.
The output result is as follows:
If you get the same output as above, congratulations! -- You have successfully run your first Python program.
If you get an error, check that the program you typed is correct and run it again. Python is case sensitive. print and Print are different, and text indentation is also important!
Next! In my opinion, Beginners should be familiar with the most stable Editor, that is, our own programming language editor. So for those who have learned the basics, we should be more familiar with the other editor, that is, Pycharm.
3. PyCharm Editor (advanced)
PyCharm is a handy Python editor I have used. It can also be used across platforms and in both macos and windows, which is better. First, preview the PyCharm interface in practical application: (changed the default style of PyCharm)
Next, I will not elaborate on the PyCharm download process. I will leave a message to ask!
So our words are coming! I finally waited until I got started. Can't help it!
4. Basic Input and Output in Python
Just like reading English, the meaning of input is vt. [from] [Electronic] input... Enter the computer. The raw_input Statement of version 2.74 is used here.
Raw_input is a Python built-in function that reads the input in the console and interacts with users.
Let's take a look at two examples:
We can see that both functions can receive strings, but raw_input () directly reads the input from the console (any type of input can be received ). For input (), it is expected to be able to read a valid python expression, that is, you must enclose the string with quotation marks, otherwise it will cause a SyntaxError.
We can see that raw_input () treats all input as strings and returns the string type. Input () has its own characteristics when dealing with pure numeric input. It returns the type of the entered number (int, float). At the same time, we know in Example 1 that input () accept valid python expressions. For example, input (1 + 3) returns 4 of the int type.
5. Python outputs the print function statement.
The output print function is like a big bag! It can eat everything! The visitor is not rejected! :)
No matter what type, value, Boolean, list, dictionary... Can be directly output.
6. Output dialog box
The most successful programming language is the windows operating system created by Bill. This kind of window style makes it easier for people to understand and intuitively shows a software operation and makes great progress in this era.
Then we will begin to learn how to output the language into a dialog box.
TkMessageBox. FunctionName (title, message [, options])
Parameters:
-
- FunctionName: the name of the corresponding message box function.
- Title: The text displayed in the title bar in a message box.
- Message: the text to be displayed as a message.
Options: there is an alternative option. You can use it to customize a standard message box. Some available options are default and parent. The default options are used to specify the default buttons, such as abort, retry, or ignore them in the message box. The parent option is used to specify the top-level window in the message box to be displayed.
(Today, we will go to the super entry point. This is the cornerstone. This is the start of your success! So I look forward to you becoming a great Bull !!!!!)