1、变量名
一般使用字母、数字、下划线,首行顶格开始写,一般不以下划线作为变量名开头,数字不能用作变量名开头。
不能与关键字一致,尽量不与内置函数一致。
import keyword
print("打印出关键字,不用硬记住")
print(keyword.kwlist)
2、内存存储地址
a = 100
print(id(a))
3、执行其中一行代码
#选中需要运行代码,alt+shift+E
4、变量自增
a = 1
a += 1
print(a)
a -= 1
print(a)
a *= 2
print(a)
a /= 2
print(a)
5、拼接
print('abc'+'def')
print('abc'+ 123)#TypeError: must be str, not int
print(123 + 'abc')#TypeError: unsupported operand type(s) for +: 'int' and 'str'
6、序列
a = [1,2,3,4,5,6,7,8]
print(a[0],a[-len(a)])
print(a[10])#IndexError: list index out of range( 数值越界)
7、切片[第一刀:第二刀:步长]
info = 'abcdef'
print(info[1:1+2])#一般使用第一刀位置+上取值长度
print(info[:2])#填后取前
print(info[2:])#填前取后
print(info[0:5:2])#步长跳转取值
print(info[::-1])#反序写