Python learning notes (1), Python learning notes (

Source: Internet
Author: User

Python learning notes (1), Python learning notes (
I. Definition and Configuration

Python is an easy-to-learn and easy-to-use language. Because of its clear and easy-to-understand code, it helps students not to tangle in complicated code syntaxes and enjoy the fun of programming as an object-oriented language, at the same time, it has excellent scalability and portability. You can select code from a module or read attributes from another module. Many "Predecessors" have developed a variety of extension libraries. No matter what applications you want to develop, you may find similar code modules or even "Plug and Play ". General Software written in Python on any platform can run on other platforms with slight modifications or even no modifications required.


Visit the official website of Python: http://python.org, download and install, and then open IDLE, in which you can write code, but also equipped with Python Shell, to show the results of code running.

Python Shell can interact with each other. For example, all input after your program runs is in Python Shell.


Ii. Basic Concepts

First read a piece of code

myString = "Sin_Geek"myNum1 = 24myNum2 = 0x92myNum3 = 1234567890987654321Lprint myNum1print myNum2print myNum3print myString
Very concise. The entire code segment is to assign values to variables and then print the output variables ~~ (ER, compared with the C language, you do not need to include header files or write the MAIN function. What's important is that you do not need to write the variable type or a semicolon! The output is concise !), It is convenient to assign values to the variable, whether it is an integer, a string, or another type of value.

If it is an octal, hexadecimal, or long integer value, you only need to add a mark before or after it. See the code above.

The Length Integer in Python is different from that in C or other compiled languages. It does not need to be 32-bit or 64-bit. The length of a long integer in Python depends on the size of the (virtual) memory supported by your machine. In other words, as long as the content is sufficient, it can express a large value.

Then, as an advanced language, there must be several "internal" data types, as shown below:

myList = [1, 2, "python", 1.2]myTuple = (1, 2, "python", 1.2)myDict = {'name':'sin_geek', 'height':'180' 'age':23}print myListprint myTupleprint myDict
You can see from the English language that lists, tuples, and dictionaries.

Then, the loop syntax is divided into the while and

counter = 0while counter < 5:    print counter    counter += 1

items = [1, 2, 3, 4, 5]for item in items:    print item,

Through the above code, we can see that although Python does not have braces, it requires four spaces to represent each level of indentation (but in actual writing, you can customize the number of spaces, but the number of spaces must be equal for each indentation ). As the indentation depth increases, the layers of the code block are also deepened. The code block without indentation is of the highest level. This indentation is strictly controlled. The interpreter will determine the part of the current Code based on the indentation, that is, indentation replaces the braces.

Next we will introduce how to compile the function. First, the def before the function name indicates that the function is followed by the function, and then add a colon at the end of the parentheses. The indent part is the function content.

def printMyName(name):    print nameprint MyName("sin_geek")
Next Five operations

u = 1v = 24print "u+v=",u+vprint "u-v=",u-vprint "u*v=",u*vprint "u/v=",u/vprint "u%v=",u%v
Run the command to check whether the division result is an integer. If you want to obtain a decimal number, you need to introduce an external module to implement this function.

from __future__ import divisionprint 24/7
Note that the underscores on both sides of the future are two ~~

Then there is a string with single quotation marks, double quotation marks, and three quotation marks, which are used in different cases. In general, single quotation marks and double quotation marks are used. However, it is best to use double quotation marks to indicate that single quotation marks exist in strings, of course, you can also use the \ escape character to indicate the single quotation marks in the string. The three quotation marks are used when the string is too long for Branch writing.

To be continued ~





I just learned Python and used Python30. I recommend a book for beginners.

The release of python3.0 is not long before. We recommend that you use more than 2.7, with less information and less answers to problems.
First look at the python simple tutorial, and then look at the python core programming.
After learning, you can easily develop a crawler tool. If you want to research the web, you can study django, which will make you excited!

This is my learning path.

I have always been helpful!

Who can recommend the best PYTHON learning material?

We recommend that you use python2.X for python learning notes and learning python in pidaqing.

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.