keyword-argument - 如何在类中为关键字参数提供预定义值?(Python)
问题描述
这是另一个愚蠢的问题:我想给我的结果键一个预定义的值,在这个例子中,“是”将获得值 A,然后“否”将获得值 B,如果我有第三个结果,它将获得值 C 等等on,我不想自己添加值,我希望类自动添加它。我该怎么做?
class bettingPool():
def init(self, mesageId, bookie, betText, stake, **outcome):
self._messageId = mesageId
self._bookie = bookie
self._betText = betText
self._stake = stake
self._outcome = outcome
我必须如何制作我的对象:
betPool1 = bettingPool("1", "player1", "will it work?", 20, yes=A, no=B)
我想如何制作我的对象:
betPool1 = bettingPool("1", "player1", "will it work?", 20, yes, no) <- the class would assign the value A and B to "yes" and "no" automatically.
解决方案
推荐阅读
- photoeditorsdk - 将 PESDK 主题更改为白色
- java - BufferedReader(System.in) readLine() 方法返回 IOException,Stream 已关闭
- android - 警报未在同一日期触发
- arrays - VBA中的数组循环而不保留
- c# - 我应该在我的 UWP 应用程序中使用哪些蓝牙功能从我的 BLE 设备中读取字符
- python - Python Django 从 DateField 中按月获取不同的查询集
- matlab - 如何将两个矩阵列明智地组合为用逗号分隔的字符串?
- unity3d - 属性 [Emission] [number field] 不可见,因为该对象无法在瞭望台上
- javascript - Vue 指令设置或修改元素属性
- javascript - 使用 jinja 每页加载一定数量的项目