立即学习:https://edu.csdn.net/course/play/25498/304502?utm_source=blogtoedu
除法、次方:
10/3 = 3.3333333(正常)
9/3 = 3.0
10 //3 = 3 (结果取整)
10 % 3 = 1(取余数)
2**2 = 4 (2的2次方)
2**3 = 8(2的8次方)
字符串切片
变量名[起始下标:结束下标:步进]
常用字符串函数:
len()计算字符串长度
replace()替换字符串中的特殊字符
index()返回字符串位置的下标
find()查找字符串
split()分割字符串
字符串拼接方式:
(1)+号:str = ‘北京’+‘你好’
(2)list拼接:
list_str = ['ni','hao','bei','jing']
str2 = ' '.join(list_str)
(3)format拼接:先占位,后期赋值
str3 = '我喜欢{},因为我需要{}'.format('python','赚钱')
print(str3)
s = 'abcdef'
s[1]:b
s[0]:a
字符串切片:
s ='abcdefgh'
s = s[0:3]-------abc
s = s[:4]------abcd
s = s[2:]------defgh
s = [:-1]------abcdefg(从第一个到倒数第二个)
s = s[::2]-------aceg(间隔2个取)