IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: 1.1.0
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

ord

def ord(s: StringSpan) -> Int

Returns an integer that represents the codepoint of a single-character string.

Given a string containing a single character Codepoint, return an integer representing the codepoint of that character. For example, ord("a") returns the integer 97. This is the inverse of the chr() function.

This function is in the prelude, so you don't need to import it.

Args:

  • ​s (StringSpan): The input string, which must contain only a single- character.

Returns:

Int: An integer representing the code point of the given character.