*和**

表达式中 **两个乘号就是乘方,比如2**4,结果就是2的4次方,结果是16 一个乘号*,如果操作数是两个数字,就是这两个数字相乘

iohannes iohannes Published on 2025-03-17

单列模式

使用模块 myclass.py class myclass( ): def fun(self): pass instance = myclass() call.py import myclass a = myclass.instance __new__

iohannes iohannes Published on 2025-03-17

导入上级目录包

整体目录结构 |-- comm | |-- prim_joint_set.py | |-- prim_position_set.py |-- app | |-- entity | | |-- init.py | |-- http_srv.py app.entity.__init__py import

iohannes iohannes Published on 2025-03-17

动态添加属性和方法

person.py class Person(): def __init__(self,name): self.name = name main.py from person import Person li = Person('李') # 动态添加属性 li.age = 20 prin

iohannes iohannes Published on 2025-03-17

合并两个有序数组

def merge_two_sort_list(a:list, b:list) ->list: new_list = [] a_len = len(a) b_len = len(b) a_index = 0 b_index = 0 while a_in

iohannes iohannes Published on 2025-03-17

类继承

class a: def __init__(self, name): self.name=name class b: def __init__(self, p1, p2): self.p1=p1 self.p2=p2 class c(a,b): def __i

iohannes iohannes Published on 2025-03-17

类型注解

类型注解 自python3.5开始,PEP484为python引入了类型注解(type hints)。类型检查,防止运行时出现参数和返回值类型、变量类型不符合。作为开发文

iohannes iohannes Published on 2025-03-17

类的常见函数

class Person(): #创建一个类 def __init__(self): print('这是一个初始化方法。') def comm_fun(self): print('这是一个普通方法。') @staticme

iohannes iohannes Published on 2025-03-17

枚举

from enum import Enum # pip install enum34 class Build(Enum): debug = 200 build = 400 string to enum a=Build[‘debug’] output: ‘400’ enum to s

iohannes iohannes Published on 2025-03-17

排序

map 排序 map_xxx ={} map_xxx[1] ='a' map_xxx[3] = 'c' map_xxx[2] = 'b' for k, v in map_xxx.items(): print(k) result = sorted(map_xxx.keys()) result

iohannes iohannes Published on 2025-03-17
Previous Next