Mojo object对象详解及相关说明

object

Defines the object type, which is used to represent untyped values.

These are Mojo built-ins, so you don’t need to import them.

Attr

A generic object’s attributes are set on construction, after which the attributes can be read and modified, but no attributes may be removed or added.

Fields:

  • key (StringLiteral): The name of the attribute.

  • value (object): The value of the attribute.

Implemented traits:

AnyType

Methods:

__init__

__init__(inout self: Self, key: StringLiteral, owned value: object)

Initializes the attribute with a key and value.

Args:

  • key (StringLiteral): The string literal key.
  • value (object): The object value of the attribute.

object

Represents an object without a concrete type.

This is the type of arguments in def functions that do not have a type annotation, such as the type of x in def f(x): pass. A value of any type can be passed in as the x argument in this case, and so that value is used to construct this object type.

Aliases:

  • nullary_function = fn() raises -> object: Nullary function type.

  • unary_function = fn(object) raises -> object: Unary function type.

  • binary_function = fn(object, object) raises -> object: Binary function type.

  • ternary_function = fn(object, object, object) raises -> object: Ternary function type.

Implemented traits:

AnyType, Boolable, IntableRaising, Stringable

Methods:

__init__

__init__(inout self: Self)

Initializes the object with a None value.

__init__(inout self: Self, impl: _ObjectImpl)

Initializes the object with an implementation value. This is meant for internal use only.

Args:

  • impl (_ObjectImpl): The object implementation.

__init__(inout self: Self, none: None)

Initializes a none value object from a None literal.

Args:

  • none (None): None.

__init__(inout self: Self, value: Int)

Initializes the object with an integer value.

Args:

  • value (Int): The integer value.

__init__(inout self: Self, value: SIMD[f64, 1])

Initializes the object with an floating-point value.

Args:

  • value (SIMD[f64, 1]): The float value.

__init__[dt: DType](inout self: Self, value: SIMD[dt, 1])

Initializes the object with a generic scalar value. If the scalar value type is bool, it is converted to a boolean. Otherwise, it is converted to the appropriate integer or floating point type.

Parameters:

  • dt (DType): The scalar value type.

Args:

  • value (SIMD[dt, 1]): The scalar value.

__init__(inout self: Self, value: Bool)

Initializes the object from a bool.

Args:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

启航学途

您的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值