Python Study Notes 01-basics, python Study Notes 01 --

Source: Internet
Author: User

Python Study Notes 01-basics, python Study Notes 01 --
I. interpreted language

Python is an interpreted language, which means:

L The compiled code can be run without compiling connections, saving debugging time

L python interpreters are well implemented in most systems, so the compiled code can run in any system.

However, this also means:

L interpretation execution efficiency is relatively low, so the program running efficiency is also relatively low. intuitively speaking, it is a long running time.

 

Ii. application fields

Despite its shortcomings, python is definitely an excellent programming language. Any language has its own applicable fields and scenarios. The main application fields of python include:

L develop the gadgets required by daily use, including script tasks required by the system administrator.

L Web programming, such as website development and background services. The efficient features of python make it especially suitable for the agile development of websites, so that functions can be iterated quickly. There are already many frameworks available in the web field, such as flask and django.

L as the adhesive for other languages. A common situation is to first use python to develop a system prototype. The key performance part or the part with special requirements can be rewritten using c/c ++, which is called by python.

Iii. Installation version

L a program written in Python needs to be run by the interpreter. Therefore, downloading python is essentially a python interpreter. Due to the popularity of python, the interpreter version is more than one, usually used version is CPython, that is, the interpreter written in C language, from the official website (https://www.python.org /) the download is the CPython interpreter. For windows systems, download and install them directly. The installation method is a silly installation.

L Python currently has two versions, namely 2. there are many differences between x and 3.x, and all messages are displayed 2. version x will be phased out gradually, and the official team is also pushing forward 3. python 3.x is recommended.

L after the installation is successful, enterPythonOr find python in the Start menu (windows installation) to open the interactive mode of python:

* Here's>>>Indicates that the interactive mode has been entered.

* Enter exit () and press enter to exit interactive mode.

So what is the purpose of this interaction mode? Interactive Mode Provides a function that allows you to immediately display the results of your written code, which is useful for learning and debugging programs.

Iv. Basics 1. Print the output statement Print

In interactive mode, enter:

PRint ('Hello World ')

Note that there is no semicolon at the end, and the semicolon is not required at the end of the python statement.

All single quotes and double quotes in Python indicate strings.

Press enter to see the output.

 

2. Get user input

Python3 notRaw_inputNow

For input functions, all inputs are treated as strings:

3. Numbers and expressions ü addition, subtraction, multiplication, division, and remainder are also applicable in python.

Note: Division has two forms in python:/And//For dividing 1 by 2:

1/2 of the Results faithfully follow our expectation, while 1 // 2 is 0, because // represents the division of integers, and the result is still an integer, the decimal places are ignored.

Ü multiplication operator **

** Represents the multiplication party,2 **3The result is 8, while-3 ** 2The result is-9. Note that the priority of the multiplication party must be greater than the negative number. Therefore, if you want to require the square of-3, you need to add brackets:

 

Ü python3 can process long integers freely without adding U hexadecimal and octal integers.

Hexadecimal number0xStart

Octal0oStart

 

4. Common functions ü multiplication function pow

2 ** 3 is the same as pow (2, 3)

Ü absolute value function abs U rounded to round5. module U usage:

1.Direct importImport math

>>> import math>>> math.floor(32.9)32

2.Simple ImportFrom math importSqrt

>>> from math import sqrt>>> sqrt(9)3.0
Ü cmath Module

The math module cannot process virtual data.

Cmath can handle Virtual numbers:

>>> import cmath>>> cmath.sqrt(-1)1j
Ü use the _ future _ module to provide support for new features 6. Save and execute ü write code through IDLE

In Windows, python has built-in IDLE. With this tool, no other IDE is needed.

Run the python script through a command prompt. Run the script like a normal program.

Add the following to the file header line in unix:

#!/usr/bin/env python

Make the script executable:

$ chmod a+x hello.py

Enter the file name to run the task.

$ hello.py

If python is correctly installed in Windows, double-click it.

Note: The program will flash, so you need to add a line at the end of the program:

input(‘Press <enter>’)
7. Note #8. String U single quotes double quotation marks mixing U Escape Character \ U concatenated string

Two adjacent strings are interpreted as one string.

Plus sign concatenation string

Ü convert to string

Str () and repr ()

Ü long string

Use'''To wrap the newline string.

Line breaks can also be enclosed in single quotes.\This method also applies to expressions and statements.

Ü original string R '' ÜUnicode string U ''

Python3 supports unicode by default.

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.