python基础

来源:互联网 发布:手机遥控玩具车软件 编辑:程序博客网 时间:2024/06/16 19:39




Python 3.6(版本不一样, 可能有些命令的格式不太相同)


一、内容简介:
1、Python执行的过程:
source  code(.py)----> complier(PVM) ---> bytecode(.pyc)  --->  Interpreter ---> processor

2、cpython(原始标准实现方式)
Jpython(java语言集成方式)
IronPython(.net框架集成)

3、python的性能优化工具:


Psyco


Pypy

shed skin

4、Python程序可以由模块 语句 表达式  对象组成
一切皆对象
面向过程:(以指令为中心  指令处理数据  怎样组织代码问题)
面向对象:(以数据为中心  所有代码以数据为中心, 如何设计组织数据结构)


5、dir(platform) 查看函数














1、输出格式:
常规输出
>>>print("hello")
>>>hello

输出整数
>>>print("number is : %d"%d(89))
>>>number is : 89

输出字符串
>>>print ("His name is : %s"%("lmy"))
>>>His name is : lmy

输出单精度:
>>>print("number is : %f"%(1.83))
>>>number is : 1.830000


>>>print("number is : %.3f"%(1.83))
>>>number is : 1.830

占位符:
>>>print ("Name:%10s Age:%8d Height:%8.2f"%("lmy",25,1.83))
>>>Name:    lmy  Age:      25  Height:     1.83

>>>print ("Name:%-10s Age:%-8d Height:%-8.2f"%("lmy",25,1.83))
>>>Name:lmy   Age:25     Height:1.83


2、python的运算和表达式
1 / 2  =0.5
1 // 2  =0
2 * 3  = 6
2 ** 3 = 8
-2 ** 3 = -8
(-2) ** 3 = -8
abs(x) 绝对值
divmod(x,y)  x除以y所得的商和余数
pow(x,y)  等于 **
pow(x,y,z) 等于 (x**y)%z
round(x,n)四舍五入到小数后位


二进制:binary
>>>0b1000
8

八进制:octal(数字0,字母o)
>>>0o123
83


十六进制:hexadecimal
>>>0xAB
171

3、整数转换函数
bin(i)  i的二进制
hex(i)  i的十六进制
int(i)  x转换成整数
int(s,base) 
oct(i) i的八进制


4、整数位逻辑操作符
i | j
i ^ j
i & j
i << j
i >> j
~i 

5、身份操作符
>>>a = ["dd",3, one]
>>>b = ["dd", 3, one]
>>>a is b
  false
>>> a = b
>>>a is b
   true
>>>3 in a (in用来测试成员关系)
true
6、python的关键字
and        as     assert      break    class
continue   def    del         elif     else
except     False  finally     for      from
global     if     import      in        is
lambda     None   nonlocal    not       or
pass       raise  return      True     try
while      with   yield


7、math模块
>>>import math
math.acos(x)
.acosh(x)
.asin(x)
...
8、复数
>>>z=-89.5+2.125j
>>>z.real, z.imag
(-89.5, 2.125)
>>>z.conjugate()
>>>3-4j.conjugate()

9、十进制数
>>>import decimal
>>>a = decimal.Decimal(8976)
10、>>>del x 用于删除x对象


11、序列类型:
1)元组:元组是一个有序序列,包含0个或者多个引用对象
2)元组分片:
>>>h = "h1", "h2", "h3","h4"
>>>h[2]
>>>h[2:]
>>>h[-2:]
>>>h[1:3]
>>>h[2:-1]
>>>h[:2]+("g",)+h[2:]  元组进行连接
3)列表:


12、五种内置序列类型:
1)bytearray  bytes  list  str  tuple 

14、集合类型:
set  可变的
frozenset  固定的

15、字典:
dict 一种无序的组合数据类型,其中包含0个或者多个键值对

原创粉丝点击