Python复习(拾遗)

一

摩尔定律

  单位面积集成电路可容纳晶体管数量每两年翻倍:CPU ,GUP, 内存, 硬盘 的价格都与此有关

  C1972

  python1990

计算机 两种方法编译(类似翻译)和解释(类似同声传译)     把源代码(人)编译为目标代码(机器)

  依据执行方式不同

    静态语言C/C++ Java 编译执行 快

    脚本语言 python 慢
输入 输出 处理
        处理:利用算法


  
eval(字符串或者字符串变量)
错误:eval("hello")
因为hello不是字符串

turtle库

import turtle
turtle.setup(1000,1000,0,0)
turtle.goto(200,200)
turtle.goto(200,-200)
turtle.goto(0,0)

turtle.goto(-200,200)
turtle.goto(-200,-200)

turtle.goto(-100,-100)



turtle.circle(100,360)
turtle.bk(200)
turtle.fd(400)

turtle.seth(90)
turtle.fd(300)
turtle.seth(180)
turtle.fd(300)

turtle.penup()
turtle.fd(-600)
turtle.pendown()

turtle.pensize(10)
turtle.pencolor("purple")
turtle.fd(300)

for i in range(6):
    turtle.fd(100)
    turtle.left(60)
    
turtle.penup()
turtle.fd(300)
turtle.pendown()

for i in range(9):
    turtle.fd(100)
    turtle.left(40)
import<库名>as<库别名>

Python整数
    pow()
    整数无限制
    四种进制 12 0B12 0O12 0X12 还有BOX小数也可以
浮点数:与数学中实数一致
    取值范围和精度基本无限制
    有取值范围 精度10e-16
    浮点数运算存在不确定尾数,不是bug,发生在16位左右
    0.1+0.2==0.3
    False
    round(0.1+0.2,16)==0.3 True
    round(0.1+0.2,17)==0.3 False
    科学计数法 4.3e-1==0.43
复数 与数学中复数观念一致 3+4j
运算符 略
运算函数
    abs
    divmod(x,y)
    pow()
    round()
    max() min() int() float() complex()
字符串
    索引和切片 "12345"[-1]    "12345"[:-1] "1234567890"[3:8:2]
    字符串处理函数
        len str hex oct chr ord 
    方法 指某一种函数,<a>.<b>()该函数b和a有关
        字符串的方法
        str.lower() upper  split count replace center(20,"++")
        strip join 
    字符串的格式化
        掌握format方法
            "{1:*>30},{0:=^20}".format("111","222") 可以作用于字符串和数字
            "{0:,.3f}".format(56332.334567)   ,.2f只能用于数字
            "{2:*>30,.2f}  {1:-^20}   {0:+<10}".format("123","456",789000.9999)     
程序的分支结构
    单
        if True:
            执行
    
    双  if True:
            执行A
        else:
            执行B
    多  if elif...else
    
    异常处理
    try except

猜你喜欢

转载自www.cnblogs.com/xinqidian/p/10188219.html
今日推荐