Python core tutorial (version 2) Reading Notes (1)

Source: Internet
Author: User


Chapter 1 WelcomePythonWorld

 


File Extension

    Python source files are usually extended using. py. When the source file is loaded or explicitly compiled by the interpreter, It is compiled into bytecode. Because different methods are used to call the interpreter, the source file will be compiled into a file with the. PyC or. Pyo extension.

     

    Standard library path

      In ubuntu9.10, the library functions of python2.6 are installed in the/usr/lib/python2.6 folder by default.

       

      PythonFile Path

        In python, the executable file python is installed in the/usr/bin folder.

         

         

        Chapter 2 Quick Start

           

        PythonPrompt in interpreter

          In the python interpreter, there are two kinds of prompts: >>> the main prompt is the interpreter telling you that it is waiting for you to enter the next statement .... The prompt is a prompt that tells you that the interpreter is waiting for you to enter other parts of the current statement.

           

          Statements and expressions

            Statement usageKeywordsCommand. It is similar to telling the interpreter a command. If you tell Python what to do, it will do for you. The statement can have output or no output. For example, print "Hello world" is a statement.

            ExpressionNo keyword.They can be arithmetic expressions made up of mathematical operators or functions called using parentheses. They can accept user input, or do not accept user input. Some may have output, while others may not. For example, ABS (4) is an expression that accepts the input of a value and then outputs the absolute value of the value.

             

            The print statement calls the STR () function to display objects, while the interactive interpreter calls the Repr () function to display objects.

             

            The underscore (-) has a special meaning in the interpreter, indicating the last one.Expression.

             

            The easiest way to get data input from a user is to use the raw_input () built-in function. It reads the standard input and assigns the read data to the specified variable. You can also use the INT () built-in function to convert your input string to an integer. For example:

             #coding=utf8

            name =raw_input("Please enter you name:")

            age = int(raw_input("Please enter you age:"))

            print "Yourname is %s,you are %d year-old" %(name,age)

             

             

             

             

             

             




            Note

              Method 1: Comment. The content starting from '#' and ending with a line is annotated.

              Method 2: Use three single quotes or three double quotes for comments. This is a special annotation. It is generally called "document string ". You can add a string at the beginning of a module, class, or function to provide online document functions. Different from common annotations, document strings can be accessed at runtime or automatically generated.

               

              Python currently provides two comparison operators "not equal to": "<>" and "! = ". ABC/Pascal and C respectively. Currently, the former has been gradually eliminated. We recommend that you use the latter.

               

              Python supports expressions similar to 3 <Y <22. It is equivalent to: "Y> 3and Y <22"

               

              The Python variable name is case sensitive.

               

              Python is a dynamic type language, that is, the type of the variable does not need to be declared in advance. Variables to types and values are initialized at the moment of value assignment. Variable value assignment is executed by equal signs.

               

              Python supports Incremental assignment. That is, operators and equal signs are combined. Example:

              N * = 1 is equivalent to N = N * 1

               

              Python does not support the auto increment 1 and auto increment 1 operators. This is because + and-are also single-object operators. python will interpret-n as-(-n) to get n, and the result of ++ n is also n.

              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.