基本数据类型:
数字
字符串
布尔值
列表
元祖
字典
所有对象所具备的功能都保存在相应的类中。
查看对象的类,或对象所具备的功能。
1、通过type()查看
temp = "alex"
t = type(temp)
2、整体查看dir()快速列举
temp = "alex"
t = type(temp)
print(dir(t))
3、查看某类型的功能
temp = "alex"
t = type(temp)
help(type(t))
4、鼠标点击
temp = "alex"
temp.upper()
鼠标放在upper()上,Ctr+左键,自动定位到upper功能
基本数据类型的常用功能:
整型int
n1 = 123
n2 = 456
print(n1+n2) #实际是调用了n1的方法
print(n1.__add__(n2))
a1 = "alex"
ret = a1.capitalize()
print(ret)
a1 = "alex"
ret = a1.center(20,'*')
print(ret)
结果:********alex********
a1 = "alex is alph"
ret = a1.count("a")
print(ret)
a1 = "alex is alph"
ret = a1.count("al",0,10) #从0到10
print(ret)
temp = "hello"
print(temp.endswith('e',0,2)) 结果:True
content = "hello\t999"
print(content)
print(content.expandtabs())
print(content.expandtabs(20))
s = "alex hello"
print(s.find("ex"))
s = "hello {0}, age{1}"
print(s)
new1 = s.format('alex',19)
print(new1)
Python range()函数
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
for i in range(10): print(i) 0 1 2 3 4 5 6 7 8 9
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
new_list = ['this','is','a','book'] for i in range(len(new_list)): print(i,new_list[i]) 0 this 1 is 2 a 3 book
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
new_list = range(10) new_list Out[41]: range(0, 10) type(new_list) Out[42]: range
list 中 append()和extend()用法
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
mylist = [1,2,'abc','nice'] mylist.extend(['day','night']) mylist Out[68]: [1, 2, 'abc', 'nice', 'day', 'night'] mylist.extend([120,119]) mylist Out[71]: [1, 2, 'abc', 'nice', 'day', 'night', 120, 119]