python基础(3)

这篇博客详细介绍了Python的基础知识,包括Python对象的分类如标准类型、数字类型等,深入探讨了数字中的整型、长整型、浮点型、复数型及其操作,如类型获取、切片、比较、布尔运算。还讲解了类型函数如Abs()、divmod()、pow()等的用法以及进制转换和ASCII转换函数。
摘要由CSDN通过智能技术生成
Python对象
1、标准类型

整形、布尔型、长整形、浮点型、复数型、字符串、列表、元组、字典

2、Type()获取特定对象的类型信息
>>> type(42)
<class 'int'>

在这里插入图片描述

>>> type(type(42))
<class 'type'>

在这里插入图片描述

3、切片对象
>>> foostr="abcde"
>>> foostr[::-1]
'edcba'
>>> foostr[::-2]
'eca'
>>> foolist=[123,"xba",342.23,"abc"]
>>> foolist[::-1]
['abc', 342.23, 'xba', 123]

在这里插入图片描述

4、对象值的比较
>>> 2==2
True
>>> 2.46 <= 8.33
True
>>> "abc"  == "xyz"
False
>>> "abc"  >= "xyz"
False
>>> "abc" <  "xyz"
True
>>> [3,"abc"] == ["abc",3]
False
>>> [3,"abc"] == [3,"abc"]
True
>>> 3<4<7
True
>>> 4>3==3
True
>>> 4<3<5  != 2<7
False

在这里插入图片描述

>>> foo1=foo2=4.3
>>> foo2
4.3
>>> a=[5,"hat",-9.3]
>>> b=a
>>> a is b
True
>>> a is not b
False
>>> b=2.5e-5
>>> b
2.5e-05
>>> a
[5, 'hat', -9.3]
>>> a is b
False
>>> a is not b
True

在这里插入图片描述

>>> a=1
>>> id(1)
1349479440
>>> b=1
>>> id(b)
1349479440
>>> c=1.0
>>> id(c)
109516034576
>>> d=1.0
>>> id(d)
109516034552

在这里插入图片描述

5、布尔类型

操作优先级从高到低:not、and、or

>>> x,y= 3.1415926536,-1024
>>> x<5.0
True
>>> not(x<5.0)
False
>>> (x<5.0)and(y>2.718281828)
False
>>> not(x is y)
True

在这里插入图片描述

6、type()

type()接受一个对象作为参数,并返回它的类型,它的返回值是一个类型对象。

>>> type(object)
<class 'type'>
>>>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值