温故知新,总结前4天所学知识!
"""
第五天学习,复习前四天的知识点,并在原有知识点基础上,引入新的内容。
"""
#1.变量赋值,切记,变量命名不可以关键字命名
a = 10
b = "hello world"
c = ["a", "b", "c"]
d = []
d[:2] = 10, 20
# 2.数据类型,可通过type()来获取变量的类型
# 2.1 数字
a1 = 10 # 整型
b1 = 1.2 # 浮点型
c1, d1 = True, False # 布尔型
# 2.2 字符串
# 2.2.1字符串多种赋值方式
str1 = 'hello world'
str2 = "hello world"
str3 = """
hello
world
"""
# 2.2.2字符串的方法
s = " hello, world "
s1 = ['127', '0', '0', '1']
s.upper() # 转大写
s.isdigit() # 判断字符串是否为数字
s.strip() # 去掉前后空格
s.split(",") # 以逗号切割为列表
".".join(s1) # 将序列中的元素以指定的字符连接生成一个新的字符串
s.index("h") # 字符串h的下标是几
s.count("l") # 统计字符在该字符串中出现的次数
"*".center(10, "=") # 以*为中心输出10个=
s.startswith("h") # 字符串是否以h开头
s.endswith("a") # 字符串是否以a结尾
# 2.2.3 字符串操作符
s = "hello "
p = "world"
print(s + p) # 字符串相加 "hello world"
print(s * 5) # 输出5个字符 "hello hello hello hello hello "
print("a" in s) # 字符"a"是否在s中存在 False
print("h" in s) # 字符"h"是否在s中存在 True
print("a" not in s) # 字符"a"不在s中 True
print("h" not in s) # 字符"h"不在s中 False
2.2.4 字符串索引和切片
z = "abcdefghi"
print(z[0]) # 字符串列表中的第一个字符
print(z[2]) # 字符串列表中的第三个字符
print(z[-1]) # 字符串列表中的倒数第一个字符
print(z[-2]) # 字符串列表中的倒数第二个字符
print(z[:3]) # 从开始取值到下标为3结束 不包含3
print(z[2:5]) # 下标从2开始到5结束 不包含5
print(z[2:-1]) # 下标从2开始到倒数第一个结束 不包含倒数第一个
print(z[-1::]) # 从倒数第一个开始,到结束
print(z[::2]) # 步长为2 也就是间隔为2
print(z[::-1]) # 倒着输出全部
"""
2、当天总结
(1).变量与赋值
(2).数字型,字符型的相关知识
数字型:整型:a = 10
浮点型:b = 1.23
布尔型:c,d = True,False
字符型:
多种赋值
字符串的方法:upper()、isdigit()、strip()、split()
join()、index()、count()、center()
startswith()、endswith()
字符串操作符:+、*
成员关系:in 、not in , "a" in str
字符串索引与切片:list[0]、list[-1]、list[:2]、list[::2]、list[0:3:-1]等
知识回顾
(1).索引 p[2]
(2).切片 p[:2]
(3).成员关系:in
(4).列表:a = ["1","2","3"]
(5).strip() 去掉字符串前后空格
(6).变量、赋值:phone = "13812345678"
(7).and 和 or:and是且的关系;or是或的关系
(8).数据类型:布尔型(True\False) 字符串(str)
(9).几种内置方法:dir()、help()、print()、len()、isdigit()、type()
(10).条件语句:if...else... if条件的语句块,前边的缩进四个空格或一个Tab键
"""