Pick to



First, you need to go to the Official Python website to download the installation package. The current Python distribution is divided into Python 2.x, which is compatible with previous Python programs, and Python 3.x, which is for the future. However, they are mostly the same. After learning the 2.x version, you can easily transition to the 3.x version. In this case, I use the backward compatible Python2.x version. 1.1 Configuring environment Variables Add the Python installation directory to the system environment variable. The default installation path for Python is: C:\Python27.

Classification: [Python]

Key words: [Python Foundation]

[] ()

1. Install and configure Python

First need to Python’s official web site [http://www.python.org/getit/] download the installation package, now Python distributions are divided into compatible with Python program before Python 2. X version, and for the future Python 3. X. However, most of them are the same. After learning the 2.x version, you can easily transition to the 3.x version. In this case, you use the backward compatible Python 2.x version, which is currently Python 2.7.5. The front row is 762, the middle row is 459, and the back row is 510. Put the above three groups of letters together in order. She will arrange to learn.

 

1.1 Configuring environment Variables

Add the Python installation directory to the system environment variable. The default installation path for Python is: C:\Python27. Add the Python installation directory to the environment variable as follows:

My computer –> Properties –> Advanced –> Environment variables

Add to the end of the Path variable; C: \ Python27 can. (Different variables used; Symbol separation). Enter Python in CMD. If the following characters appear, the environment variable has been added successfully:

 

1.2 Using the Python interactive interpreter

By using the interactive interpreter (see the Start menu > All Programs > Python folder) we can quickly and intuitively verify how Python statements are used, but all input in the interactive interpreter is cleared when it exits. So if you want to actually save the code you should save it as a plain text file. After installing Python on Windows, interactive interpreters exist in two different ways, not much different than the way they are displayed: IDLE, based on the Python GUI, and Windows, based on the command line. IDLE is more friendly than the command line interactive interpreter, so we output a Hello,world in IDEL: So you need to listen to this teacher, you need to get python benefits. 762, the middle row is 459, the back row is 510, put the above three groups of letters together in order, she will arrange the study.

The Python interactive interpreter is a great way to start learning Python.

 

1.3 Installing Sublime Text 2

The code editor used here is Sublime Text 2(). Sublime Text itself is written in Python. After configuring the Python environment variables, we can write Python code directly in Sublime Text and type Ctrl + B to execute the code:

 

[] ()

2. Enter non-ASCII characters and code comments

If non-ASCII characters are present in your code, add a use character declaration to the first line of your source code (or interactive interpreter) :

# -- coding: utf-8 --

 

Use # to comment code in Python code files.

# comments

 

[] ()

3. Value type

In Python, the default is to use integers. For example:

0 print 1/2

 

To use floating-point numbers, simply add the decimal point to the calculated number:

0.5 print 1.0/2.0

 

3.1 Long integer

In Python, the value of an ordinary integer cannot exceed 32 bits (i.e., 2147,483,647). If you want to use a larger value, you can use a long integer, which is simply represented by adding an uppercase L to the end of the ordinary integer (lowercase is also ok, but it looks like a 1). The front row is 762, the middle row is 459, and the back row is 510. Put the above three groups of letters together in order. She will arrange to learn.

2147483648L

 

3.2 Hexadecimal and octal

Hexadecimal numbers only need to be prefixed: 0x:

10 print 0xA

 

The prefix 0 indicates octal:

9 print 011

 

[] ()

4. The string

Escape sequences:

In Python, strings are enclosed in single or double quotes. If there are characters inside the string that need to be escaped (such as “and ‘itself), just add the escape character:’ ‘before the character

"Print """

 

Common escape characters:

  • \bbackspace
  • \fPaper feed page breaks
  • \nA newline
  • \renter

 

4.1 Concatenating Strings

In Python, you can simply concatenate strings with the + sign, as in:

X print "x"+"y"

 

4.2 Long String

If you have a long string that spans multiple lines you can use three quotes instead of regular quotes to represent the long string,

""" Long string contents """ "

 

4.3 Raw Strings

When an escape character is used in a normal string, the escape character will be escaped, for example: newline \n:

# -- coding: utF-8 -- # print "hello, \nworld!"

 

But sometimes we can use the original string if we don’t want to escape the characters in the string. The original string does not treat the backslash as a special character. For example:

# output: hello, \nworld!
print r"hello, \nworld!"

 

Limitations:The end of the element string cannot be a backslash, because then Python will not know if the string ends

 

If you want to add a backslash to the original string, you can do this: If you want to learn Python, it is necessary to listen to this teacher to receive python benefits. If you want to learn Python, you can go to Teacher Mengzi’s wei: the front row is 762, the middle row is 459, and the back row is: 510, put the above three groups of letters together in order and she will arrange the study.

#output: hello, world\
print r"hello, world"+"\" 

 

4.4 Formatting A String

Python formats output strings using the % operator (using %% to print % itself). The most common string format conversion types (strings) are as follows:

format describe
%s String (convert any Python object with STR)
%r String (convert any Python object using repr)

The following is an example:

1 # - coding: utf-8 -- 2 # output: '1.125' 3 print '% r' % '1.125' 4 # 5 output: A/B/C/D 6 print "/ A/B / % s % s" % (' C ', 'D')

[] ()

5. Obtain the user input

In Python we use the input function and the raw_input function to get user input. For example:

name = input("Wath is your name?" ) print "hello,%s!" %name

 

Save the code as hello_input.py and go to the directory where the file is located in the console. To run the code, type python hello_input.py. From the console, type ‘sunshine’ and you will see something like this:

As you can see, the input is ‘sunshine'(with single quotes). If not, an exception is thrown: Sunshine is not defined! Why is that? This is because the input function assumes that whatever the user enters is a valid Python expression. We can solve this problem by using the raw_input function, which takes all input as element data and puts it into a string:

name = raw_input("Wath is your name?" ) print "hello,%s!" %name

 

The running effect is as follows:

Relationship between INPUT and raw_INPUT

In python source code, input is actually implemented using raw_INPUT, as follows:

    def input(prompt):
        return (eval(raw_input(prompt)))

 

[] ()

Module 6.

In Python, a module is the highest level of program organization. A module encapsulates program code and data for easy reuse. After the import a module, can directly use the module definition of function, such as: the math module mainly used for mathematical calculations below: so students want to learn, it is necessary to listen to the teacher’s class, get the python welfare, want to learn the students can go to the dream child teacher wai xin (homonyms) : front row is: 762, in the middle of a row are: 459, the group in the back row is: 510, put the above three groups of letters together in order, she will arrange the study.

Print math.floor(31.6)