id 函数可以查看内存地址
-------- -5 到 256之间的只有一个地址也就是说存地址存一份,值就会 相同




python常用的内置对象

解释说明:
一个表达式里不能同时出现数字类型和字符串类型------因为不会自动强制转换
number型 和 bool型 可以混合,单独两个各自也可以自动转换
数字-----只有相加可以正确输出

数字查看分子分母、创造分数对象
变量 . numerator
变量 . denominator
Fraction(m,n)

高精度实数运算

编码函数 encode 解码函数 decode



text = "你好,世界!"
encoded_text = text.encode('utf-8') # 将字符串编码为UTF-8格式的字节串
print(encoded_text) # 输出:b'\xe4\xbd\xa0\xe5\xa5\xbd\xef\xbc\x8c\xe4\xb8\x96\xe7\x95\x8c\xef\xbc\x81'

encoded_text = b'\xe4\xbd\xa0\xe5\xa5\xbd\xef\xbc\x8c\xe4\xb8\x96\xe7\x95\x8c\xef\xbc\x81'
decoded_text = encoded_text.decode('utf-8') # 将UTF-8格式的字节串解码为字符串
print(decoded_text) # 输出:你好,世界!
注意 :如果编码和解码时使用的不是同一种编码方式,可能会导致错误或产生不可预测的结果。因此,在处理数据时,请确保始终使用一致的编码方式。
class ------ 在python中是类的意思
# 定义一个名为"Dog"的类
class Dog:
# 初始化方法,当创建一个新的Dog对象时会自动调用
def __init__(self, name, age):
self.name = name # 设置对象的name属性
self.age = age # 设置对象的age属性
# 定义一个方法,用于描述狗的行为(例如:叫)
def bark(self):
print(f"{self.name} says: Woof!")
# 创建一个Dog对象,并给它指定名字和年龄
my_dog = Dog("Buddy", 3)
# 访问对象的属性
print(my_dog.name) # 输出:Buddy
print(my_dog.age) # 输出:3
# 调用对象的方法
my_dog.bark() # 输出:Buddy says: Woof!
在这个例子中,我们定义了一个名为Dog的类 ,它有两个属性(name和age) 和一个方法**(bark)** 。然后,我们使用这个类创建了一个名为 my_dog的对象 ,并设置了它的属性。最后,我们调用了my_dog的bark方法,让它叫了一声。
# 定义一个名为"Person"的类
class Person:
# 初始化方法,当创建一个新的Person对象时会自动调用
def __init__(self, name, age):
self.name = name # 设置对象的name属性
self.age = age # 设置对象的age属性
# 定义一个方法,用于描述人的行为(例如:打招呼)
def greet(self):
print(f"Hello, my name is {self.name} and I am {self.age} years old.")
# 创建一个Person对象,并给它指定名字和年龄
person1 = Person("Alice", 30)
# 访问对象的属性
print(person1.name) # 输出:Alice
print(person1.age) # 输出:30
# 调用对象的方法
person1.greet() # 输出:Hello, my name is Alice and I am 30 years old.
在这个例子中,我们定义了一个名为Person的类,它有两个属性(name和age)和一个方法(greet)。然后,我们使用这个类创建了一个名为person1的对象,并设置了它的属性。最后,我们调用了person1的greet方法,让它打了一个招呼。
赋值两变量、三变量

数字中的分子分母定义分数
numerator -------- 分子
denominator --------- 分母

高精度的 Decimal

次方的表示

复数类型:
共轭复数: conjugate
虚部: imag
实数: real
复数的绝对值:abs()
拼接 + :
相同类型可以省略 +

不同类型不能省略

ASCLL:
0: 48
空格: 32
大写A:65
小写a: 97
\n < 空格 < 数字 < 英文
字符串前面相同,字符串长的 ascll 值大
空字符串比任何字符串都小------True
in:是成员
is:是 是
False == 0
not in 和 is not 都是否定的
位运算符:注意位与

eg:3 & 4 == 0011 和 1100 == 结果就是0000
3 | 4== 0011 和 1100 == 结果就是 0111 == 7
按位与 & :只要有0 在结果就是0
或 | :只要有1 在结果就是1
位运算符:

集合运算符:

补充:
补集 == 并集 - 交集

xor:异或
or:与或
左移右移
左移:*2的倍数------ 后面补0
右移:/2的倍数------- 前面补0
左移一位×2,左移两位×4
右移一位/2,右移两位/4
逻辑短路:
and 两个都必须成立
运算从左开始
and如果第一个为 False------结果就是 False 后面的不算 >>>> 惰性计算
or如果第一个是True -------- 结果就是True
惰性计算的函数:不运行就不会报错,如果用他的结果就会报错
map函数 == 映射函数


注意:end 要加等号
end=' '
end' ' --------报错
提取三位数的各个位的数 :map 和 divmod函数使用


#.join(s) 和 split 互为反函数
sorted函数使用