Skip to main content

Mojo function

int

int[T: Intable](value: T) -> Int

Get the Int representation of the value.

Parameters:

  • T (Intable): The Intable type.

Args:

  • value (T): The object to get the integral representation of.

Returns:

The integral representation of the value.

int[T: IntableRaising](value: T) -> Int

Get the Int representation of the value.

Parameters:

  • T (IntableRaising): The Intable type.

Args:

  • value (T): The object to get the integral representation of.

Returns:

The integral representation of the value.

Raises:

If the type does not have an integral representation.

int(value: String, base: Int = 10) -> Int

Parses the given string as an integer in the given base and returns that value.

For example, atol("19") returns 19. If the given string cannot be parsed as an integer value, an error is raised. For example, atol("hi") raises an error.

If base is 0 the the string is parsed as an Integer literal, see: https://docs.python.org/3/reference/lexical_analysis.html#integers

Args:

  • value (String): A string to be parsed as an integer in the given base.
  • base (Int): Base used for conversion, value must be between 2 and 36, or 0.

Returns:

An integer value that represents the string, or otherwise raises.

int(value: UInt) -> Int

Get the Int representation of the value.

Args:

  • value (UInt): The object to get the integral representation of.

Returns:

The integral representation of the value.