Think Python 笔记-print、cmd、除法

    技术2022-07-11  86

    1.print知识冷点

    print可以不是函数。 作为语法结构,是保留关键字: print"hello world" 作为函数,有括号: print(hello world) 返回值: 永远是1.

    2.CMD的部分用法。

    以下操作在windows中。 -启动cmd的方法: -win+r得运行,输入cmd。

    以下在代码cmd中。 安装扩展包的方法: pip install numpy 启动解释器的方法 python 测试延迟: ping www.2345.com 查看计算机名 hostname 查看网络相关信息: ipconfig

    3.除法"/,//,%,divmod,round,ceil,floor"重点

    >>>print(84/2)#没有小数,结果就没有小数 42 >>>print(84.0/2,84/2.00,84/2.01)#有小数,结果有小数,通常保留一位除非位数很多 (42.0, 42.0, 41.791044776119406) >>>print(84.0//2,84.5//2,85//2,85.999//2)#//的含义为整除,结果与被除数同类型 (42.0, 42.0, 42, 42.0) >>>print(84.0%2,84.5%2,85%2,85.999%2)#%的含义为取余,结果与被除数同类型 (0.0, 0.5, 1, 1.9989999999999952) >>>a,b=divmod(85.999,2)#证明了a,b=divmod(M,N)等效为a,b=(M//N,M%N),用后一种可增加可读性 >>>print(a,b) >>>print(85.999//2,85.999%2) (42.0, 1.9989999999999952) (42.0, 1.9989999999999952) >>>import math >>>print(round(3.14159),math.ceil(3.14159),math.floor(3.14159)) #round()四舍五入,ceil()上取整,floor()下取整
    Processed: 0.012, SQL: 9