python学习笔记-数据类型和操作-Day2

❤️❤️写在前面:本笔记内容参考Datawhale聪明办法学python书写。❤️❤️

一、常用内置类型 BUILTIN TYPES

  • 整数 Integer(int)
  • 浮点数 Float
  • 布尔值 Boolean(bool)
  • 类型 Type (你没看错,"类型" 也是一种类型)
  • 字符串 String (str)
  • 列表 List
  • 元组 Tuple
  • 集合 Set
  • 字典 Dictionary(dict,或者可以叫它 映射 map)
  • 复数ComplexNumber (complex)
  • 函数Function 
  • 模块 Module
  • str、list、tuple、set、dict 将尝试用 数组 Array 的方式讲授

(课程上说,Type 是一种 类 的 对象,python是一门“面对对象友好”的语言 ,说实话,我没听懂 )

print(type(2))
print(type(2.2))
print(type(2<2.2))
print(type(type(42)))
print(type("2.2"))
print(type([1,2,3]))
print(type((1,2,3)))
print(type({1,2}))
print(type({1:42}))
print(type(2-3j))
print(type(f))
print(type(math))
'''
终端显示:
<class 'int'>
<class 'float'>
<class 'bool'>
<class 'type'>
<class 'str'>
<class 'list'>
<class 'tuple'>
<class 'set'>
<class 'dict'>
<class 'cumplex'>
<class 'function'>
<class 'module'>
'''

二、内置常数 BUILTIN CONSTANTS

  • Ture 布尔
  • False 布尔
  • None ,用于空值
  • 一些数学常量:

pi ,常数π=3.141592.. 精确到可用精度
e ,常数e=2.718281..精确到可用精度
tau ,τ=6.283185..精确到可用精度 (其实它不常用)
inf ,浮点正无穷大,等价于 float('inf'),负无穷大使用 -math.inf

import math
print(math.pi)
print(math.e)
print(math.tau)
print(math.inf)
print(-math.inf)
'''
终端显示:
3.141592653589793
2.718281828459045
6.283185307179586
inf
-inf
'''

三、常用内置运算符 BUILTIN OPERATORS

  • 算术 : + , - , * , @(矩阵乘法) , /(浮点除) , // (整除), **(多少次方) , %(取余) , - (一元算符), +(一元算符)

注意 取模运算 和 取余运算 的区别 !!!

  • 关系 : く , <= ,>=,>,==(逻辑运算,判断) ,  !=(不等)
  • 赋值 : =, +=,-=,*=,/= , //=,**=,%=
  • 逻辑 : and , or,not
  • 按位运算符(暂不学习)

四、运算符优先级 OPEERATOR ORDER

优先级从高到低表格:

五、短路求值 SHORT-CIRCUIT EVALUATION

  • 逻辑运算参照表:

  • 短路运算:

如果X已经能够判断该表达式的值,那么,就不会再判断Y了。 

六、type() VS isinstance()

  • isinstance() 比 type() 更具有 稳健性(Robustness)
  • 这种做法更加符合 面向对象编程 中 继承(inheritance) 的思想
  • 推荐使用 isinstance()

例子如下:

  • 6
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值