【问题标题】:How to check the type of the parameterized constructor arguments?如何检查参数化构造函数参数的类型?
【发布时间】:2020-05-13 13:36:58
【问题描述】:
def __init__(self, data=None, item=None, user=None, seed=1):
    """
    Parameterized constructor
    """
    # data for creating features
    self.data = data
    self.item = item
    self.user = user

现在如何检查 self.data 中的数据类型是什么?

【问题讨论】:

标签: python python-3.x constructor parameter-passing


【解决方案1】:

你可以使用:

print(type(self.data))
print(type(self.item))
print(type(self.user))

【讨论】:

    【解决方案2】:

    使用type()函数获取变量类型信息:

    类类型(对象)

    使用一个参数,返回对象的类型。返回值是一个类型对象,一般与object.__class__返回的对象相同。

    【讨论】:

      猜你喜欢
      • 2011-06-08
      • 2017-05-19
      • 1970-01-01
      • 2015-09-04
      • 1970-01-01
      • 2010-12-05
      • 2012-09-22
      • 1970-01-01
      • 2012-02-08
      相关资源
      最近更新 更多