A basic knowledge of small
1, if the line of code is too long, can be used ULink \
wrap Writing
example
if (signal == "red") and \ (car == "moving"): car = "stop" else : pass
Equivalent to
if (signal == "red") and (car == "moving"): car = "stop" else : pass
2, without line breaks
Two cases:
A, parentheses, brackets, internal braces can write multiple lines
b, including the three quoted strings can write interbank
example
print('''nicholas is a smart boy. When I was just a little boy, I asked my mother, What will I be? Will I be pretty? Will I be rich ?''')
3, a multi-line statements
separated by;
例子
x = "Today" ; y = "is" ; z = "Thursday" ; print(x,y,z)
Generally do not write, unless there is a lot of contact.
4, in python, the python with the same indentation level represents the same block.
5, in python, the names of the variables are case insensitive (PI and pi are different variables).
6, try not to begin with an underscore, to underscore the interpreter has a special meaning, is the built-in symbolic identifiers used generally as a private.
7, try not to use the variable name spelling.
8, various operators
Priority order of operators, the operator with increasing priority:
Lambda # operator has the lowest priority logical operators: or logical operators: and logical operators: not members of the test: in, not in identity test: is, is not comparison: <, <=,>,> =, =! , == bitwise oR: | bitwise XOR: ^ bitwise aND: & shift: <<, >> addition and subtraction: +, - multiplication, division and modulo: *, /,% sign: + x, -x
9, python assignment
a, with the assignment =
pi = 3.1415926
b, the incremental assignment
m + = 1 immediately = M Tasu M 1
M ** = 2 immediate m = m ** 2
c, chain assignment
PI = pi = 3.1415926
Analysis: Here is the first 3.1415926 assigned to pi, and then continue to assign PI.
d, multiple assignment
Are equal on both sides so as to appear tuple
example
PI, r = 3.1415926,3
Analysis: Here is 3.1415926 assigned to PI, 3 assigned to r. In fact, are equal on both sides tuple, parentheses are usually written as
(PI, r) = (3.1415926,3)
Second, the basic data types Tips
1, boolean in fact, is a subclass of integer, only two values, namely True \ False, essentially a store integer of 1,0.
2, complex-type, real + imaginary number is plural, which is similar to the imaginary square root of a negative number.
Imaginary part must have j.
Complex can be separated from the real and imaginary parts
with .real and .imag
example
Third, modules, packages
1, the non-built-in module introduced
import * from module name
or
import the module name
2, a complete document that is a python module
- File: physical organization math.py
- Module: the logical organization math
3, introducing a plurality of modules
import module name, module name
import ModuleName1,ModuleName2
If you want to import the module module in the specified property, that is, it specifies the name of the import of the current scope
can write
from Module1 import ModuleElement
is to import all the attributes and classes of the modules are introduced, from Module1 import ModuleElement manner is introduced into the class attributes and parts
4, packing (package)
Package is a hierarchical file directory structure, package defines a Python application package consisting of modules and sub-execution environment.
example
AAA/ _init_.py bbb.py CCC/ _init_.py c1.py c2.py DDD/ _init_.py d1.py EEE/ ...
这里AAA最顶层的包,CCC、DDD就是子包
如果要调用CCC下的c1模块
import AAA.CCC.c1
AAA.CCC.func1(123)
或者
from AAA.CCC.c1 import func1
func1(123)
5、库
库一组具有相关功能的模块的集合
python的一大特色就是具有强大的标准库、以及第三方库、以及自定义模块
在实际当中可能把库和模块混在一起说。
一、基础小知识点
1、如果一行代码过长,可以用续行符 \
换行书写
例子
if (signal == "red") and \ (car == "moving"): car = "stop" else : pass
等同于
if (signal == "red") and (car == "moving"): car = "stop" else : pass
2、无需换行符的情况
两种情况:
a、小括号、中括号、大括号内部可以多行书写
b、三引号包括下的字符串可以跨行书写
例子
print('''nicholas is a smart boy. When I was just a little boy, I asked my mother, What will I be? Will I be pretty? Will I be rich ?''')
3、一行多语句
用;分隔
例子
x = "Today" ; y = "is" ; z = "Thursday" ; print(x,y,z)
一般不会这样写,除非有很大的联系。
4、在python中,python用相同的缩进表示同级别的语句块。
5、在python中,对变量的名字大小写是敏感的(PI和pi是不同的变量)。
6、尽量不要用下划线开头,下划线对于解释器有特殊的意义,是內建标识符使用的符号,一般会当做私有的。
7、变量名尽量不要用拼音。
8、各种运算符
运算符的优先级顺序,以下运算符的优先级依次递增:
Lambda #运算优先级最低 逻辑运算符: or 逻辑运算符: and 逻辑运算符:not 成员测试: in, not in 同一性测试: is, is not 比较: <,<=,>,>=,!=,== 按位或: | 按位异或: ^ 按位与: & 移位: << ,>> 加法与减法: + ,- 乘法、除法与取余: *, / ,% 正负号: +x,-x
9、python赋值
a、用 = 赋值
pi = 3.1415926
b、增量赋值
m +=1 即 m = m + 1
m **= 2 即 m = m ** 2
c、链式赋值
PI = pi = 3.1415926
分析:这里首先是将3.1415926赋值给pi,然后继续赋值给PI。
d、多重赋值
等号两边都以元组的方式出现
例子
PI,r = 3.1415926,3
分析: 这里是将3.1415926赋值给PI,3赋值给r。等号两边其实都是元组,一般会都加上括号写成这样
(PI,r) = (3.1415926,3)
二、基础数据类型小知识
1、布尔型其实是整型的子类,仅有两个值即True\False,本质上是用整型的1、0分别存储的。
2、复数型,实数+虚数就是复数,虚数就是类似负数的平方根。
虚数部分必须有j。
复数可以分离实数和虚数部分
用.real和 .imag
例子
三、模块、包
1、非內建模块导入
from 模块名 import *
或者
import 模块名
2、一个完整的python文件即是一个模块
-文件:物理上的组织方式 math.py
-模块:逻辑上的组织方式 math
3、导入多个模块
import 模块名,模块名
import ModuleName1,ModuleName2
如果要导入模块里指定的模块属性,也就是吧指定名称导入当前作用域
可以这样写
from Module1 import ModuleElement
import是把模块的所有属性和类都导入,from Module1 import ModuleElement的方式是导入部分的属性和类
4、包(package)
包是一个有层次的文件目录结构,包定义了一个由模块和子包组成的Python应用程序执行环境。
例子
AAA/ _init_.py bbb.py CCC/ _init_.py c1.py c2.py DDD/ _init_.py d1.py EEE/ ...
这里AAA最顶层的包,CCC、DDD就是子包
如果要调用CCC下的c1模块
import AAA.CCC.c1
AAA.CCC.func1(123)
或者
from AAA.CCC.c1 import func1
func1(123)
5、库
库一组具有相关功能的模块的集合
python的一大特色就是具有强大的标准库、以及第三方库、以及自定义模块
在实际当中可能把库和模块混在一起说。
一、基础小知识点
1、如果一行代码过长,可以用续行符 \
换行书写
例子
if (signal == "red") and \ (car == "moving"): car = "stop" else : pass
等同于
if (signal == "red") and (car == "moving"): car = "stop" else : pass
2、无需换行符的情况
两种情况:
a、小括号、中括号、大括号内部可以多行书写
b、三引号包括下的字符串可以跨行书写
例子
print('''nicholas is a smart boy. When I was just a little boy, I asked my mother, What will I be? Will I be pretty? Will I be rich ?''')
3、一行多语句
用;分隔
例子
x = "Today" ; y = "is" ; z = "Thursday" ; print(x,y,z)
一般不会这样写,除非有很大的联系。
4、在python中,python用相同的缩进表示同级别的语句块。
5、在python中,对变量的名字大小写是敏感的(PI和pi是不同的变量)。
6、尽量不要用下划线开头,下划线对于解释器有特殊的意义,是內建标识符使用的符号,一般会当做私有的。
7、变量名尽量不要用拼音。
8、各种运算符
运算符的优先级顺序,以下运算符的优先级依次递增:
Lambda #运算优先级最低 逻辑运算符: or 逻辑运算符: and 逻辑运算符:not 成员测试: in, not in 同一性测试: is, is not 比较: <,<=,>,>=,!=,== 按位或: | 按位异或: ^ 按位与: & 移位: << ,>> 加法与减法: + ,- 乘法、除法与取余: *, / ,% 正负号: +x,-x
9、python赋值
a、用 = 赋值
pi = 3.1415926
b、增量赋值
m +=1 即 m = m + 1
m **= 2 即 m = m ** 2
c、链式赋值
PI = pi = 3.1415926
分析:这里首先是将3.1415926赋值给pi,然后继续赋值给PI。
d、多重赋值
等号两边都以元组的方式出现
例子
PI,r = 3.1415926,3
分析: 这里是将3.1415926赋值给PI,3赋值给r。等号两边其实都是元组,一般会都加上括号写成这样
(PI,r) = (3.1415926,3)
二、基础数据类型小知识
1、布尔型其实是整型的子类,仅有两个值即True\False,本质上是用整型的1、0分别存储的。
2、复数型,实数+虚数就是复数,虚数就是类似负数的平方根。
虚数部分必须有j。
复数可以分离实数和虚数部分
用.real和 .imag
例子
三、模块、包
1、非內建模块导入
from 模块名 import *
或者
import 模块名
2、一个完整的python文件即是一个模块
-文件:物理上的组织方式 math.py
-模块:逻辑上的组织方式 math
3、导入多个模块
import 模块名,模块名
import ModuleName1,ModuleName2
如果要导入模块里指定的模块属性,也就是吧指定名称导入当前作用域
可以这样写
from Module1 import ModuleElement
import是把模块的所有属性和类都导入,from Module1 import ModuleElement的方式是导入部分的属性和类
4、包(package)
包是一个有层次的文件目录结构,包定义了一个由模块和子包组成的Python应用程序执行环境。
例子
AAA/ _init_.py bbb.py CCC/ _init_.py c1.py c2.py DDD/ _init_.py d1.py EEE/ ...
Here AAA top-level package, CCC, DDD is subpackages
If you are calling c1 module at CCC
import AAA.CCC.c1
AAA.CCC.func1(123)
or
from AAA.CCC.c1 import func1
func1(123)
5, the library
Module library associated with a collection of functions
A major feature is a powerful python standard library, as well as third-party libraries, as well as custom modules
In practice the libraries and modules may mix said.