Python Study Notes (half ZZ and half self-written)

Source: Internet
Author: User
Tags natural string
What is Python Language

Python is a computer programming language. It is used in computer programming languages like c/c ++/java/perl/VB/Delphi, it is also an advanced object-oriented language that is widely used and can be expanded. Python can run on almost all computers, such as Windows, Linux, FreeBSD, and Solaris, or on mobile phones. It supports Java and. Net technologies. Python (parson) is an object-oriented programming language that is widely used and has clear syntax features. It is suitable for multiple operating systems, it can be run on Windows and Unix systems. It is very popular internationally and is being applied more and more. Python can complete many tasks with powerful functions. Python core website is: http://www.python.org/, where you can find a lot of information. If you use Python for the first time, you can download a try.

Python is easy to use and does not require complex compilation. It is widely used and can be used for various software development, such as website, GUI, network programming, and database programming, graphic image processing, scientific computing, mobile programming, and so on.

Google is the most widely used Python Company (google's cloud computing platform GAE supports the default Python), which is the Google search engine that people can see everywhere. Microsoft has also begun providing software in the Python language (the IronPython architecture on the. NET platform value makes everything more likely to change ). Nokia, a world-renowned mobile phone manufacturer, has already begun providing mobile phone development software based on the Python language. In addition, many games are developed using Python. Another famous company is Zope, and youtube is all developed in Python. There are not many companies using Python in China, but only some Web 2.0 companies. However, because of its simple and clear syntax, it is suitable for completing various high-level tasks and can run in almost all operating systems. Therefore, its related technologies are developing rapidly, the number of users has expanded dramatically and there are a lot of related resources. Over time, many software companies will start to use it on a large scale.

The English word "Python" is pronounced as "Parson", so Chinese can be called Parson.

Download and install

· Go to Python.org to download. We recommend that you download version 2.5 + because version 3.0 + is still in the testing stage.

After Python is installed, it comes with an IDE development environment IDEL (of course, compared to VS, which is several times more lightweight). Of course, you can also use any text editor to compile Python, of course, there are also many visual advanced IDE development environments to compile Python programs (such as Wing IDE and komodo ), if IronPython is used, you can also use Visual Studio to write Python programs (the traditional Python is implemented in C, namely CPython, and JPython ).

The first "Hello World" program

First, create a new notepad file on the desktop and change the name to helloworld. py (the python program uses py as the extension by default, you can also change it to another name), right-click to open it with IDEL, of course, it is empty. Type

Print "Hello world"

Then press F5 to run the program. The program is very simple. We can output the result in a special command line:

Syntax

Although the Python syntax is very concise, it is not a sentence or two. I have sorted out some basic points.

I. Basic Concepts

1. Number: integer, long integer, floating point number (for example, 3.23 or 52.3E-4), and plural (for example:(-5+4j)Or(2.3-4.6j)]

2. String:

(1) The strings in double quotation marks are identical to those in single quotation marks.

(2) You can use three quotation marks (''' or ") to indicate a multi-line string.

(3) Escape Character [\], but a separate backslash at the end of a string line is used to continue the line

(4) Natural string: it is specified by adding the prefix r or R to the string so that it remains unchanged (not escaped)

(5) Unicode string: prefix u or U before the string, for example, u "this is unicode" <o: p> </o: p>

3. variables: when using variables, you only need to assign them a value. No need to declare or define data types

4. identifier: It is composed of letters (uppercase or lowercase), underscores ('_'), and numbers (0-9) in the alphabet. The first character must be a letter (uppercase or lowercase) or underline ('_')

5. indent: in Python, statement blocks are labeled in indentation instead of braces. That is, statements at the same level must have the same indentation.

6. Operators (Part)

(1) power operator **: x ** y returns the y Power of x. For example, 3 ** 4 = 3*3*3*3*3.

(2) Remove the integer part of the operator //: returns the integer part of the operator. For example, 4 // 3.0 returns 1.0.

(3) Boolean "Non" operator not

(4) Boolean "and" operator and

(5) Boolean "or" operator or

7. Control Flow

(1) if statement: the form is as follows: (Note that the if statement contains a colon at the end, telling Python to follow a statement block; and there is no switch statement)

1.IfCondition:

2. statement

3.ElifCondition:

4. statement

5.Else

6. statement

(2) while statement: the form is as follows:

1.WhileCondition:

2. statement

3.Else:

(3) for statement: the form is as follows:

1.ForElementInCollection:

2. statement

3.Else:

(4) break statement: similar to other languages, it should be noted that if it is terminated from the for or while LOOP, no corresponding loop else block will be executed

(5) continue statement: same as other languages

8. function: defined by the def keyword. The def keyword is followed by the identifier name of a function, followed by a pair of parentheses. Variable names can be included in parentheses, which end with a colon. Next is a statement, which is the function body, for example:

1.DefFunction_name ():

2. statement

[Note] Python has a wonderful feature called document string, which is usually referred to as docstrings. A document string is a multi-line string (three quotation marks are required). Its first line starts with an uppercase letter and ends with a full stop. The second line is empty, and the detailed description starts from the third line. (Similar to javadoc, used in functions, just like the method in java ). Note: The first line of the document string is followed by the Function Definition Statement, that is, the first line of the function body is the document string.

9. module: a module is a python file. It is generally a tool set or reusable code, similar to the tool class in C.

Ii. Python built-in data structure

1. list: Variable Assignment Method: shoplist = ['apple', 'mango ', 'carrot', 'Banana'] [Variable list element]

2. tuples array: Variable Assignment Method: zoo = ('Wolf ', 'elephant', 'penguin') [the element of the tuples is unchangeable]

3. dictionary dict: Variable assignment mode: d = {key1: value1, key2: value2} [similar to the hashTable class in C]

4. sequence: the list, tuples, and strings are all sequences.

(1) index OPERATOR: gets a character of an element or string in the list/tuples.

(2) slice OPERATOR: gets a slice of a sequence, continuous element/Character

(3) eg:

1. name = 'swaroop'

2.Print'Characters 0 is ', name [0] #'s', index operator, similar to C #

3.Print'Characters 1 to 3 is ', name [] # 'wa' slice operator, similar to the Substring method in C #

In fact, Python contains a lot of content. For example, Python is different from the traditional interpreted scripting language. It will be compiled into bytecode during the first execution, and then runs the bytecode directly after execution, this. NET's DLR is a bit similar to Java's virtual machine. In short, it is to convert code into a way closer to machine code, which can improve performance.

I have compiled a Python Quick Reference Guide, as shown in

Summary:

Many people say that C # and Java are working languages, while Python and Ruby are weekend languages. In fact, they all communicate with each other and learn more to broaden their horizons, when agile development is so popular, selecting one of them is also a guarantee, isn't it? If you are familiar with Python, I believe you will like it.

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.