1基本数据类型:
数字 int
字符串 str
布尔值 bool
列表 list
元祖 tuple
字典 dict
所有字符串或者数字。字典 所具备的方法存在于相对应的值里
2查看对象的类,或对象所具备的功能
a 、temp = "alex"
t = type(temp)
print(t)
#str,ctrl+鼠标左键,找到str 类,内部所有的方法
b、temp = "alex"
b = dir(temp)
c、help(type(temp))
d、直接点击
鼠标放在upper上 ctrl+左键,自动定位到upper功能处
基本数据类型的常用功能:
1.整数,int
a。 n1=123
n2=456
print(n1+n2)
print(n1._add_(n2))
b。
获取可表示其二进制的最短位数
n1 = 4
ret = n1.bit_length()
print(ret)
2.字符串
##判断字符串
# s = "Alex SB"
# ret = "SB" in s
# print(ret)
##判断字符串是否在数组中
# li = ['alex','eric','rain']
# ret ="alex" in li
# print(ret)
##大小写转换
# temp = "hey"
# print(temp)
# temp_new = temp.upper()
# print(temp_new)
##资费类型
# temp = 'hey'
# help(type(temp))
##获取可表示其二进制的最短位数
# n1 = 4
# ret = n1.bit_length()
# print(ret)
# #首字母大写
# a1 = "alex"
# ret = a1.capitalize()
# print(ret)
##中间
# a2 = "alex"
# ret = a2.center(20,'*')
# print(ret)
# #找字符串出现次数
# a3 = "alex isalph"
# ret = a3.count("al",0,5)
# print(ret)
# temp = "hello"
# #获取字符串大于等于0小于等于2的位置
# print(temp.endswith('e',0,2))
##空格转换
# content = "hello 1998"
# print(content)
# print(content.expandtabs(20))
##找字符的位置
# s = "alex hello"
# print(s.find("o"))
# s = "hello {0}, age {1}"
# print(s)
# #{0}占位符
# new1 = s.format('alex',19)
# print(new1)
#join连接
# li =["alex","eric"]
# s = "******".join(li)
# print(s)
##去空格
# s = " alex "
# #news = s.lstrip()去左边空格
# #news = s.rstrip()去右边空格
# news = s.strip()
# print(news)
##替换
# s = "alex is hd"
# ret = s.replace("al","bb",1)
# print(ret)
##分割
# s = "alexalex"
# ret = s.split("e")
# print(ret)
# #大小写互换
# s = "bdasjhSD"
# print(s.swapcase())
索引与切片
s = "alex"
# #while循环
# start = 0
# while start < len(s):
# temp = s[start]
# print(temp)
# start += 1
#for 循环
for item in s:
if item == "x":
print(item)
break
print(item)
# #切片
# print(s[0:2])#0<=0,1<2
# #索引
# print(s[0])
# print(s[1])
# print(s[2])
# print(s[3])
# ret = len(s)
# print(ret)
3.列表
# name = "alex"
# age = 18
# name_list = ["eirc","alex","tony"]
# #索引
# print(name_list[0])
# #切片
# print(name_list[0:2])
# #len
# print(name_list[2:len(name_list)])
# #列表内部提供的其他功能
# #append追加
# name_list.append('seven')
# name_list.append('seven')
# name_list.append('seven')
# print(name_list)
# print(name_list.count('seven'))#统计seven个数
# #iterable,可迭代的
# temp = [111,22,33,44]
# name_list.extend(temp)
# print(name_list)
# print(name_list.index('alex'))
# name_list.insert(1,'sdasda')
# print(name_list)
# #在原列表中移除掉最后一个元素,并将其赋值给a
# a = name_list.pop()
# print(name_list)
# print(a)
# #移除seven
# name_list.remove('seven')
# print(name_list)
# #倒转
# name_list.reverse()
# print(name_list)
# #排序
# name_list.sort()
# print(name_list)
# print(name_list)
# #删除指定索引位置
# del name_list[1:3]
# print(name_list)
4.元祖(不能修改,其他与list大致相同)
#name_tuple = ('me','you')
# #索引
# print(name_tuple[0])
# #len
# print(name_tuple[len(name_tuple)-1])
# #切片
# print(name_tuple[0:1])
# for i in name_tuple:
# print(i)
# #不支持删除
# del name_tuple[0]
# print(name_tuple[0])
5.字典
# li = [11,22,33,33]
# tu = (11,22,33,33)
# li[0]
# #字典的每一个元素,键值对
# user_info = {
# 0: "alex",
# "age": 73,
# 2: 'M'
# }
# # print(user_info[0])
# # print(user_info["age"])
# #循环,默认值输出key
# for i in user_info:
# print(i)
# #获取所有键
# print(user_info.keys())
# # 获取所有值
# print(user_info.values())
# #获取所有键值对
# print(user_info.items())
#
# #get根据key获取值,如果key不存在,可以指定一个默认值
# val =user_info.get('age')
# print(val)
# val = user_info.get('age111','123')
# print(val)
# #has_key 检查字典中指定key是否存在 python3里面无
# #update更新
# print(user_info)
# t = {
# "a":123,
# "b":456
# }
# user_info.update(t)
# print(user_info)
6.其它功能
# #enumrate
# li = ["电脑","鼠标","u盘",'键盘']
# for key,item in enumerate(li,1):#默认从0开始
# print(key,item)
#
# inp = input("请输入商品:")
# #字符串转换为int
# inp_num = int(inp)
# print(li[inp_num-1])
# #range用法
# print(range(0,10))
# for i in range(1,10,1):
# print(i)
# li = ["sfasd","sdasd"]
# l = len(li)
#
# for i in range(0,l):
# print(i,li[i])