When using the Python language tutorial, many people use it as a comparison with C. Let's take a look at the corresponding language differences. Only by understanding the differences between the two can we differentiate them. The first thing to note is that this is not a complete Python tutorial, because there are already too many such tutorials on the Internet and in bookstores.
The main purpose of this article is to provide C # users with a brief introduction to the Python language to save their learning time. As a C # programmer, you have enough programming knowledge. You know, Python and C # are very similar. The relationship between them is similar to that between dialects and Mandarin, rather than between English and Chinese. You just need to spend some time learning about the minor differences between Python and C #, and then compile a few small programs to get familiar with it. You will find that Python is simpler than you think.
- Object-oriented language-Python
- Introduction to the standard Python language
- Exploring simple and powerful Python language
- In-depth analysis of the mysteries of the Python language
- Summary of Python experience
In addition, the purpose of writing this serialization is not to compete in two languages, not to encourage anyone to completely switch from C # To Python. My idea is simple: Take the Python tutorial as an interest and use it whenever appropriate.
Considering the popularity of the two languages, this article will mainly introduce C #2.0 and Python 2.6. Some features that already exist in Python 2.6 but are added in C #3.0 and 4.0 will also be mentioned as appropriate.
Finally, this serialization will mainly introduce the Python language tutorial. For the preliminary chapter arrangement, please refer to the article and welcome your comments or suggestions. I will adjust it as appropriate to meet your needs ). If you have the ability and time in the future, I will continue to write some GUI, Web development and other related content.
Install and configure the Python Development Environment
On the official Python website, you can download the installation package under Windows 2.6.4. Remember to add the directory of Python such as C: \ Python26) to the system PATH variable after installation.
The Python installation package comes with a simple integrated development environment-IDLE. You can also choose your favorite IDE. I personally recommend PythonWin. Its Syntax prompt function is very good and suitable for beginners. For details, see another article "Python IDE selection".)
First Program: Hello, world!
Now you can open IDLE or PythonWin, create a Python script file with the py extension, and enter the following content:
Code 1: The first Python Program
- print "Hello, world!"
Save and run it. If the output is >>hello, world! , Indicating that you have successfully compiled the first Python program, congratulations!
The above "Hello World" is almost the only way to learn any new language, as Simon Cozens, who proposed this program, said: "It is a traditional spell of the god of programming, it helps you better learn languages ".
To compare the differences between Python and C # In encoding style, a slightly more complex "Hello, world" program and its C # version are provided below.
Code 2: The Hello, world Program of Tang Seng Edition
- #-*-Coding: UTF-8-*-"my 2nd Python programs are only compared with C,
Decline to follow suit :)
- Import sys
- Def Main ():
- Sys. stdout. write ("Hello, world! \ N ") # The following statements look strange.
Let's explain what it is.
- If _ name _ = "_ main _": 11 Main ()
Note that line 2 of code 1st #-*-coding: UTF-8-*-is required to allow Python to support Chinese characters. If you are too troublesome, you can create a template file in IDE that only contains this line of code. This template will be automatically opened every time you create a Python script. This saves you trouble.
Code 3: Comparison of C #
- /* My 1,001st C # programs may not be available yet. I have not written so many
- */Using System;
- Class Program {static void Main (){
- If (1 = 1) // What is it? What about SQL injection?
- Console. WriteLine ("Hello, world! ")
- }
- }
-
The above are some basic Python language Tutorials that hope to help you.