共 108 篇文章 |
|
import abcclass Car: def move(self): pass def engine(self): passclass KateCar(Car): def move(self): pass def engine(self): passclass FluentCar(Car): def move(self): pass def engine(self): pass.如果使用合成复用的方式,可以这么写:class Color: passclass KateCar: color = Color() def move(self): pass def engine(self): pas... 阅18 转0 评0 公众公开 21-09-12 23:47 |
import timeimport threadingstart = time.perf_counter()def do_something(): print(''''''''-> 线程启动'''''''') time.sleep(1) print(''''''''-> 线程结束'''''''')thread1 = threading.Thread(t... 阅15 转0 评0 公众公开 21-09-11 10:15 |
详细介绍python3代码规范,小白秒懂,适合收藏。举例: 在代码的第一行,一定要首先注明编码风格 比如: # -*- coding:utf-8 -*- #推荐这种 如何调用该代码,推荐这种,在代码所在的文件夹下,打开终端输入: $ python example.py这份python代码的书写时间是2021.9.1 23:10.'''''''''''''&... 阅263 转0 评0 公众公开 21-09-03 13:22 |
moke@moke:~/gitee/moke$ python3 is_ipv4.py请输入IP地址192.168.1.100IP地址:192.168.1.100 合法moke@moke:~/gitee/moke$ python3 is_ipv4.py请输入IP地址moke.12313IP地址:moke.12313 非法moke@moke:~/gitee/moke$ 阅365 转1 评0 公众公开 21-08-30 19:05 |
32 位 Windows 系统: https://www.python.org/ftp/python/3.9.6/python-3.9.6.exe64 位 Windows 系统: https://www.python.org/ftp/python/3.9.6/python-3.9.6-amd64.exe.# 将数字数据赋值给变量 aa = 1# 将列表数据赋值给变量 aa = [1, 2, 3]# 将表达式 1 + 2 的结果值赋值给变量 bb = 1 + 2# 将表达式 b + 1 的结果值赋值给变量 bb = b + 1... 阅19 转1 评0 公众公开 21-08-11 23:47 |
scoreM = [[56,74,61,63],[63,69,65,71],[57,77,63,67],[55,76,62,62]] AssignLP += pulp.lpSum([[x[row][col]*scoreM[row][col] for row in rows] for col in cols])(4)添加约束条件 for row in rows: AssignLP += pulp.lpSum([x[row][col] for col in cols]) == 1 # sum(x(i,j),j=1,4)=1, i=1,4 for col in cols: AssignLP += pulp.lpSum([... 阅188 转0 评0 公众公开 21-08-01 05:49 |
这10个奇妙的Python库,你必须要试试。import jsonfrom urllib.request import urlopen# 全局取消证书验证import sslssl._create_default_https_context = ssl._create_unverified_contextwith urlopen(r''''''''https://jsonip.com'''''''') as fp: content = fp.read().... 阅32 转0 评0 公众公开 21-07-27 19:32 |
importmatplotlib.pyplotasplt.plt.rcParams[''''''''font.sans-serif''''''''] = [u''''''''SimHei'''''''']plt.rcParams[''''''''axes.unicode_minus'''... 阅36 转0 评0 公众公开 21-07-25 11:19 |
如果只实现 __repr__ ,则有:from datetime import datetimeclass MyDate: def __init__(self): self.date = datetime.now() def __repr__(self): return self.date.__repr__()f = MyDate()print(f)print(f.__repr__())print(f.__str__())# 输出:# datetime.datetime(2021, 6, 30, 19, 53, 14, 797960)# datetime.datetime(2021... 阅22 转0 评0 公众公开 21-07-14 19:17 |
业务人员学Python系列(2):念着口诀写代码。Python的英文意思是蟒蛇,Python的作者叫Guido(龟叔)。这句很简单直白了,是说Python代码中各种标识符是区分大小写的,也就是MyPython和mypython不是一回事。默念口诀,现在学习最简单的代码(指令):赋值语句。Python代码是由关键字、标识符、表达式和语句等构成的,语句是代码的重要组成部分... 阅115 转0 评0 公众公开 21-07-14 19:13 |