Skip to main content
Log in

Mojo function

ord

ord(s: String) -> Int

Returns an integer that represents the given one-character string.

Given a string representing one character, return an integer representing the code point of that character. For example, ord("a") returns the integer 97. This is the inverse of the chr() function.

Args:

  • s (String): The input string slice, which must contain only a single character.

Returns:

An integer representing the code point of the given character.

ord(s: StringSlice[is_mutable, lifetime]) -> Int

Returns an integer that represents the given one-character string.

Given a string representing one character, return an integer representing the code point of that character. For example, ord("a") returns the integer 97. This is the inverse of the chr() function.

Args:

  • s (StringSlice[is_mutable, lifetime]): The input string, which must contain only a single character.

Returns:

An integer representing the code point of the given character.

Was this page helpful?