为python2.7打字?
python2.7中是否有实现以下操作的方法:为python2.7打字?,python,python-2.7,types,strong-typing,Python,Python 2.7,Types,Strong Typing,python2.7中是否有实现以下操作的方法: class DailyPriceObj: def __init__(self): self.date = None #datetime.date self.sd_buy = None # float self.hd_buy = None # float self.sd_rent = None # float self.hd_rent = None #
class DailyPriceObj:
def __init__(self):
self.date = None #datetime.date
self.sd_buy = None # float
self.hd_buy = None # float
self.sd_rent = None # float
self.hd_rent = None # float
self.revenue = None # float
我在更高版本中使用过,但对于某个项目,代码库是2.7。正如您在文档中所看到的: 此GitHub repo用于开发定义的类型化模块 政治公众人物484。该模块从3.5.0版开始在Python中提供 Python 3.7.0之前的临时基础
所以,不,很遗憾,你不能在2.7中使用它 Python 2.7将于明年1月停止支持。现在必须升级请记住,Python中的类型注释只是建议——解释器不会让任何人坚持已注释的类型。话虽如此,Python 2对类型注释的唯一支持是通过每个版本的Python都是强类型的。那么,您是在问如何在Python2.7中使用类型注释吗?这是否回答了您的问题?正如@b_c在注释中所说的,您仍然可以使用python 2.7检查类型,您只需要在注释中包含注释,请参见