1、什么是数据?为何要有数据?
==> x=10,10是我们要存储的数据 。数据是用来表示状态的,不同的状态就应该用不同的类型的数据去表示
2、数据类型
A*数字(整型,长整型,浮点型,复数)
B*字符串
C*列表
D*元组
E*字典
F*集合
3、数据的使用一般是按照以下几点展开
#======================================基本使用======================================
#1、用途
?
#2、定义方式
?
#3、常用操作+内置的方法
?
#======================================该类型总结====================================
#存一个值or存多个值
#有序or无序
?
#可变or不可变(1、可变:值变,id不变。可变==不可hash 2、不可变:值变,id就变。不可变==可hash)
#AAA* 一:整型int
?
# ======================================基本使用======================================
?
# 1、用途:年龄、个数、号码、出生年等
?
# 2、定义方式
?
# age = 18 # age = int(18)
?
# int功能可以把纯数字的字符串转换成int类型
?
# res = int("18")
?
# # res = int("1.8")
?
# print(type(res))
?
# 了解(***)
?
# print(bin(11)) # 0b1011
?
# print(oct(11)) # 0o13
?
# print(hex(11)) # 0xb
?
# 3、常用操作+内置的方法
?
# 算数运算符与比较运算
?
# 二:浮点型float
?
# ======================================基本使用======================================
?
# 1、用途:薪资、身高、体重等
?
# 2、定义方式
?
salary = 3.1 # salary = float(3.1)
?
# float功能可以把浮点数组成的字符串转换成float类型
?
# res = float("1.8")
?
# print(type(res))
?
?
# 3、常用操作+内置的方法
?
# 算数运算符与比较运算
?
# ======================================该类型总结====================================
?
# 存一个值
?
# 不可变
# ======================================基本使用======================================
?
#BBB 1、用途:记录描述性质的状态,例如名字、性别、国籍等
?
# 2、定义方式:在引号(‘‘,"",‘‘‘‘‘‘,""""""")内包含一串字符串
?
s = "hello" # s = str("hello")
?
# str功能可以把任意类型转换成str类型
?
# res=str([1,2,3]) # "[1,2,3]"
?
# print(type(res))
?
# 3、常用操作+内置的方法
?
# =======================>优先掌握的操作:
?
# 1、按索引取值(正向取+反向取) :只能取
?
s = "hello world"
?
# print(s[0],type(s[0])) # "h"
?
# print(s[-1])
?
# s[1] = "E" # 不能修改
?
# 非法操作
?
# s[2222]
?
# s[11] = "A"
?
# 2、切片(顾头不顾尾,步长)=>属于拷贝操作
?
s = "hello world"
?
# new_s=s[1:7]
?
# print(new_s)
?
# print(s)
?
# new_s=s[1:7:2] #1 3 5
?
# print(new_s)
?
# print(s)
?
# new_s=s[:7:2]
?
# new_s=s[::2] # 0 2 4 6 8 10
?
# h l o w r d
?
# print(new_s)
?
# new_s=s[::] # 完整拷贝字符串,只留一个冒号就可以new_s=s[:]
?
# print(new_s)
?
?
# 3、长度len
?
# s = "hello world"
?
# print(len(s))
?
# res=print("sfd")
?
# print(res)
?
# 4、成员运算in和not in
?
# s = "hello world"
?
# # print("hel" in s)
?
# print("egon" not in s) # 语义明确,推荐使用
?
# # print(not "egon" in s)
?
# 5、移除空白strip
?
# s = " \n hel lo \t "
?
# new_s = s.strip()
?
# print(new_s)
?
# print(s) # 没有改变原字符串
?
# 应用案列:
?
# name = input("your name>>> ").strip() # name = "egon "
?
# pwd = input("your pwd>>> ").strip()
?
#
?
# if name == "egon" and pwd == "123":
?
# print(‘login successful‘)
?
# else:
?
# print(‘user or password error‘)
?
?
# 去除左右两边的非空白字符
?
# print("**+=-%^#****he**llo**%^#**+=**".strip("*+=-%^#"))
?
# 6、切分split:把字符串按照某个分隔符切成一个列表
?
# userinfo = "egon_dsb:123:18:3.1"
?
# res = userinfo.split(":")
?
# # print(res[0])
?
# print(res)
?
# print("-".join(res))
?
# 纯字符串组成的列表
?
# l = ["aaaa", "bbb", "ccc"]
?
#
?
# # res=l[0]+":"+l[1]+":"+l[2]
?
# res = ":".join(l)
?
# print(res, type(res))
?
# 7、循环
?
# for i in "hello":
?
# print(i)
?
?
# =======================>需要掌握的操作:
?
# 1、strip,lstrip,rstrip
?
# print("***hello***".strip("*"))
?
# print("***hello***".lstrip("*"))
?
# print("***hello***".rstrip("*"))
?
# 2、lower,upper
?
# msg = "AbCDEFGhigklmn"
?
# res = msg.lower()
?
# res = msg.upper()
?
# print(res)
?