python基本数据类型,,在python中的基
python基本数据类型,,在python中的基
在python中的基本数据类型有:int(数字)str(字符串)bool(布尔值) list(列表)tupel(元组) dict(字典)
类与对象的关系
如何查看对象的类?通过type来获取类型
temp = "hey"print(type(temp))
输出为:<class ‘str‘>
如何在pycharm中查看类和对象的具体功能?
方法1:str,ctr+鼠标左键,找到str类,查看内部的方法。
方法2:B=dir(temp)
方法3:通过help
help(type(temp))
方法4:直接点击方法,鼠标放在方法上ctr+鼠标左键会自动定位到功能处。
基本数据类型:int
n1 = 123n2 = 456print(n1+n2)
与
n1 = 123n2 = 456print(n1.__add__(n2))
是一样的。下划线的方法都是内置的。
查看二进制的位数:
n1 = 4ret = n1.bit_length()print(ret)
输出结果是3,说明二进制的位数是3
方法center:
a1 = "alex"ret = a1.center(20,‘_‘)
输出为
count方法:
a1 = "alex is alph"ret = a1.count(‘a1‘,0)print(ret)
输出为:
endswitch获取字符串里面大于等于0的位置小于2的位置:
temp = "hello"print (temp.endswitch(‘e‘,0,2)
content = "hello\t999"print(content)print(content.expandtabs())print(content.enpandtabs(20))
s = "hello {0}, age {1}"print(s)new1 = s.format(‘alex‘,19)print(new1)
{0}{1}占位符
在如下查看源码说明的时候,看到例如def capitalize(self)里面有self的方法,表示不用传参数,否则要在括号内写入参数。
如果有xxx = None表示默认参数,如果不传就是none,可以传也可以不传
1、数字int(整型)
在32位机器上,整数的位数为32位,取值范围为-2**31~2**31-1,即-2147483648~2147483647在64位系统上,整数的位数为64位,取值范围为-2**63~2**63-1,即-9223372036854775808~9223372036854775807
int里面重要的方法
int2、布尔值 真或假 1 或 03、字符串
"hello world"字符串常用功能:移除空白分割长度索引切片
str重要的方法
strpython基本数据类型
评论关闭