变量的使用
x = 3
print(id(x)) # 测试内存地址
print(type(x))
y = x
print(id(y)) # 按值存储 y 和x 统一空间
a = “hello world”
print(type(a))
print(isinstance(x, int))
‘’‘数字的大小 ,可表示尽可能大的数’’’
z = 99999999999999999999999999999999999999999999
x = z*z
print(x)
a1 = 1_000_000
a1 = 123
a1 = 0x123
a1 = 0o123
a1 = 0b111
a1 = 3+2j
print(a1.real)
print(a1.imag)
print(a1.conjugate())
‘’’ 字符串’’’
a = ‘abc’ # ‘’ “” "’ "’
b = a + ‘bcd’
print(b)
b = ‘xyz’‘123’
print(b)
print(‘hello\nworld’)
print(’\101’)
print(’\x41’)
算数运算符
a=10
b=4
print(a, “+”, b, “=”, a+b)
print(a, “-”, b, “=”, a-b)
print(a, "", b, “=”, ab)
print(a, “/”, b, “=”, a/b) # 不同于Java和C,结果为float
print(a, “%”, b, “=”, a%b)
print(a, "", b, “=”, ab) # a的b次幂
print(a, “//”, b, “=”, a//b) # a/b的商取整
摒弃了 ++ –
赋值运算符
x = y = z = 10 # 多变量赋同一值
print(id(x))
print(id(y))
print(x, y, z)
x,y = 1,3 # 分别对应赋值
print(x,y) # 新值覆盖了旧值
#比较运算符
a,b,c=10,20,0
print(a==b)
print(a!=b)
print(a<b)
print(a>b)
逻辑运算符
f=True
g=False
print(f and g)
print(f or g)
print(not f)
成员运算符
aList = [1,2,3,4,5,‘aass’] # 列表定义 [ ]
a = 10;
b = “aass”
print(a in aList)
print(b in aList)
aList=(1,2,3,4,5,‘aass’) # 元祖定义
a=10;
b=“aass”
print(a in aList)
print(b in aList)
字典
aDict={“name”:“aaa”,“pwd”:“123”}
x=123;
y=“name”
print(x not in aDict)
print(y in aDict)
print(aDict.values())
print(aDict.keys())
位运算
a=10
b=2
print(a>>b) # 位右移 1010 >>2 10 a//2**b
print(a<<b) # 位左移 1010<<2 101000
print(a&b) #按位与 1010 &10 0010
print(a|b) #按位或 1010|10 1010
print(a^b) #按位异或 1010^10 1000
print(~a) #按位取反 ~00001010 ==> 11110101(补码)=10001010+1=10001011