{
    "componentChunkName": "component---src-components-layout-mdx-layout-tsx",
    "path": "/language/from-python",
    "result": {"data":{"site":{"siteMetadata":{"title":"Toit documentation"}},"mdx":{"body":"const _excluded = [\"components\"];\n\nfunction _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }\n\nfunction _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }\n\nfunction _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }\n\n/* @jsxRuntime classic */\n\n/* @jsx mdx */\nconst _frontmatter = {};\nconst layoutProps = {\n  _frontmatter\n};\nconst MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  let {\n    components\n  } = _ref,\n      props = _objectWithoutProperties(_ref, _excluded);\n\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"h1\", {\n    \"id\": \"toit-for-python-programmers\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h1\",\n    \"href\": \"#toit-for-python-programmers\",\n    \"aria-label\": \"toit for python programmers permalink\",\n    \"className\": \"table-of-contents-icon before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Toit for Python programmers\"), mdx(\"p\", null, \"For readers comfortable writing Python functions and classes. Toit's indentation\\nwill look familiar, but calls, control flow, and values have different rules.\\nThis page highlights those differences. For the full language introduction,\\nread \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/language/toitversus\"\n  }, \"Toit for programmers\"), \", which explains each feature\\ndirectly and draws comparisons with C/C++, JavaScript, Python, and Java/Kotlin.\"), mdx(\"h2\", {\n    \"id\": \"indentation-is-familiar-calls-are-different\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#indentation-is-familiar-calls-are-different\",\n    \"aria-label\": \"indentation is familiar calls are different permalink\",\n    \"className\": \"table-of-contents-icon before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Indentation is familiar; calls are different\"), mdx(\"p\", null, \"Start with a function and a call. Toit uses two spaces per indentation level,\\nand the function name is followed directly by its parameters:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-toit\"\n  }, \"greet name:\\n  print \\\"Hello $name\\\"\\n\\nmain:\\n  greet \\\"Ada\\\"\\n\")), mdx(\"p\", null, \"This prints \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"Hello Ada\"), \". Spaces separate call arguments; parentheses group\\nexpressions. For example, \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"print (int.parse \\\"42\\\")\"), \" passes the parsed integer to\\n\", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"print\"), \".\"), mdx(\"p\", null, \"For a zero-argument method, writing its name calls it: \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"name.trim\"), \" invokes\\n\", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"trim\"), \". Reading a public field uses the same syntax.\"), mdx(\"h3\", {\n    \"id\": \"variables-and-names\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h3\",\n    \"href\": \"#variables-and-names\",\n    \"aria-label\": \"variables and names permalink\",\n    \"className\": \"table-of-contents-icon before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Variables and names\"), mdx(\"p\", null, \"Use \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \":=\"), \" for a new variable and \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"=\"), \" to assign it again. Variables and functions\\nuse \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"kebab-case\"), \", so \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"reading-count\"), \" is one identifier. Put spaces around\\nsubtraction, as in \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"reading - count\"), \". Comments start with \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"//\"), \".\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-toit\"\n  }, \"main:\\n  reading-count := 2\\n  reading-count = 3\\n  print reading-count  // Prints 3.\\n\")), mdx(\"h3\", {\n    \"id\": \"named-arguments\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h3\",\n    \"href\": \"#named-arguments\",\n    \"aria-label\": \"named arguments permalink\",\n    \"className\": \"table-of-contents-icon before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Named arguments\"), mdx(\"p\", null, \"Toit writes named arguments with \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"--\"), \" in both the definition and the call.\\nA default value applies when the caller omits the argument:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-toit\"\n  }, \"greet name --greeting=\\\"Hello\\\":\\n  print \\\"$greeting $name\\\"\\n\\nmain:\\n  greet \\\"Ada\\\"\\n  greet \\\"Grace\\\" --greeting=\\\"Welcome\\\"\\n\")), mdx(\"p\", null, \"This prints \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"Hello Ada\"), \", then \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"Welcome Grace\"), \". Positional parameters can also\\nhave defaults.\"), mdx(\"h2\", {\n    \"id\": \"test-emptiness-explicitly\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#test-emptiness-explicitly\",\n    \"aria-label\": \"test emptiness explicitly permalink\",\n    \"className\": \"table-of-contents-icon before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Test emptiness explicitly\"), mdx(\"p\", null, \"Only \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"false\"), \" and \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"null\"), \" are falsy in Toit. Zero, empty strings, and empty\\ncollections are truthy. Port Python's \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"if items:\"), \" as \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"if not items.is-empty:\"), \"\\nwhen the intent is to check for elements. \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"null\"), \" represents an absent value,\\nlike Python's \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"None\"), \".\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-toit\"\n  }, \"describe items:\\n  if items:\\n    print \\\"The list exists\\\"\\n  if items.is-empty:\\n    print \\\"The list is empty\\\"\\n\\nmain:\\n  describe []\\n\")), mdx(\"p\", null, \"Expected output:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-text\"\n  }, \"The list exists\\nThe list is empty\\n\")), mdx(\"h2\", {\n    \"id\": \"integer-division-truncates-toward-zero\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#integer-division-truncates-toward-zero\",\n    \"aria-label\": \"integer division truncates toward zero permalink\",\n    \"className\": \"table-of-contents-icon before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Integer division truncates toward zero\"), mdx(\"p\", null, \"Toit has signed 64-bit integers, rather than Python's arbitrary-precision\\nintegers. Integer \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"/\"), \" truncates toward zero, while Python's \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"//\"), \" rounds down.\\nA float operand gives a fractional result:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-toit\"\n  }, \"main:\\n  print (-5 / 2)   // Prints -2; Python's -5 // 2 is -3.\\n  print (5 / 2.0)  // Prints 2.5.\\n\")), mdx(\"h2\", {\n    \"id\": \"iteration-blocks-can-return-from-their-function\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#iteration-blocks-can-return-from-their-function\",\n    \"aria-label\": \"iteration blocks can return from their function permalink\",\n    \"className\": \"table-of-contents-icon before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Iteration blocks can return from their function\"), mdx(\"p\", null, \"Use \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"items.do: |item|\"), \" to iterate, and \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"items.map: |item|\"), \" to transform a list.\\nThe block's last expression is its result. A \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"return\"), \" inside a block leaves the\\nsurrounding function, making it useful for searches and early exits.\\nA block cannot be stored for later execution; use a \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"::\"), \" lambda for that.\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-toit\"\n  }, \"first-long words:\\n  words.do: |word|\\n    if word.size > 4:\\n      return word\\n  return null\\n\\nmain:\\n  print (first-long [\\\"cat\\\", \\\"horse\\\", \\\"rabbit\\\"])\\n\")), mdx(\"p\", null, \"This prints \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"horse\"), \". Returning from the enclosing function is called a\\n\", mdx(\"em\", {\n    parentName: \"p\"\n  }, \"non-local return\"), \". Use \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"continue.do\"), \" to skip an iteration without returning\\nfrom the function. Read \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/language/blocks-and-lambdas\"\n  }, \"blocks and lambdas\"), \".\"), mdx(\"span\", {\n    id: \"declare-fields-and-use-runtime-type-contracts\"\n  }), mdx(\"h2\", {\n    \"id\": \"declare-fields-in-the-class\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#declare-fields-in-the-class\",\n    \"aria-label\": \"declare fields in the class permalink\",\n    \"className\": \"table-of-contents-icon before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Declare fields in the class\"), mdx(\"p\", null, \"Toit classes declare their fields. A method cannot add new attributes to an\\nobject, so every instance has the shape defined by its class. Methods do not\\ndeclare a \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"self\"), \" parameter and can refer to fields directly:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-toit\"\n  }, \"class Person:\\n  name := ?\\n\\n  constructor .name:\\n\\n  greet:\\n    print \\\"Hello $name\\\"\\n\\nmain:\\n  person := Person \\\"Ada\\\"\\n  person.greet\\n\")), mdx(\"p\", null, \"This prints \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"Hello Ada\"), \". \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \":= ?\"), \" requires the constructor to initialize the\\nfield. The \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \".name\"), \" constructor parameter stores its argument directly in that\\nfield. Calling \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"Person\"), \" creates the object; \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"greet\"), \" is an ordinary method.\"), mdx(\"p\", null, \"When keys must be added dynamically, use a map. \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"{\\\"name\\\": \\\"Ada\\\"}\"), \" creates a map;\\nread the value with \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"person[\\\"name\\\"]\"), \". \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"{:}\"), \" is an empty map and \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"{}\"), \" an empty set.\\nSee \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/language/objects-constructors-inheritance-interfaces\"\n  }, \"classes\"), \".\"), mdx(\"h2\", {\n    \"id\": \"type-annotations-check-values\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#type-annotations-check-values\",\n    \"aria-label\": \"type annotations check values permalink\",\n    \"className\": \"table-of-contents-icon before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Type annotations check values\"), mdx(\"p\", null, \"Annotations use \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"/\"), \", as in \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"name/string\"), \", and \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"->\"), \" for a return type. Unlike\\nordinary Python type hints, Toit annotations are enforced at runtime:\"), mdx(\"pre\", null, mdx(\"code\", {\n    parentName: \"pre\",\n    \"className\": \"language-toit\"\n  }, \"length text/string -> int:\\n  return text.size\\n\\nmain:\\n  print (length \\\"Ada\\\")  // Prints 3.\\n  value/any := 42\\n  error := catch: length value\\n  if error:\\n    print \\\"Expected text\\\"\\n\")), mdx(\"p\", null, \"The \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"any\"), \" annotation permits any kind of value in \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"value\"), \". Passing it to\\n\", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"length\"), \" checks whether it is a string. The second call fails this check and\\nprints \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"Expected text\"), \". The\\nanalyzer can catch some mistakes before execution, but not every type error.\"), mdx(\"p\", null, \"Types exclude \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"null\"), \" unless marked with \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"?\"), \": \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"string?\"), \" accepts a string or\\n\", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"null\"), \". Use \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"any\"), \" to explicitly allow any value, and \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"none\"), \" for a function with\\nno result. See \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/language/definitions#type\"\n  }, \"types\"), \" for casts and type tests.\"), mdx(\"h2\", {\n    \"id\": \"ordinary-functions-can-wait\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#ordinary-functions-can-wait\",\n    \"aria-label\": \"ordinary functions can wait permalink\",\n    \"className\": \"table-of-contents-icon before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Ordinary functions can wait\"), mdx(\"p\", null, \"Toit tasks retain their call stacks while waiting for I/O. You do not need an\\n\", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"async def\"), \"/\", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"await\"), \" chain to suspend an activity. \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"task::\"), \" starts a task;\\n\", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"sleep --ms=100\"), \" suspends the current one. Within a program, tasks share objects\\nand cooperate, rather than executing as parallel threads.\"), mdx(\"p\", null, \"A loop without yielding prevents other tasks from running. A waiting library\\ncall can let shared state change before it returns. Read \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/language/tasks\"\n  }, \"tasks\"), \"\\nfor synchronization and examples.\"), mdx(\"h2\", {\n    \"id\": \"exceptions-and-imports-have-their-own-syntax\",\n    \"style\": {\n      \"position\": \"relative\"\n    }\n  }, mdx(\"a\", {\n    parentName: \"h2\",\n    \"href\": \"#exceptions-and-imports-have-their-own-syntax\",\n    \"aria-label\": \"exceptions and imports have their own syntax permalink\",\n    \"className\": \"table-of-contents-icon before\"\n  }, mdx(\"svg\", {\n    parentName: \"a\",\n    \"aria-hidden\": \"true\",\n    \"focusable\": \"false\",\n    \"height\": \"16\",\n    \"version\": \"1.1\",\n    \"viewBox\": \"0 0 16 16\",\n    \"width\": \"16\"\n  }, mdx(\"path\", {\n    parentName: \"svg\",\n    \"fillRule\": \"evenodd\",\n    \"d\": \"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"\n  }))), \"Exceptions and imports have their own syntax\"), mdx(\"p\", null, \"Use \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"throw\"), \" to raise an exception, \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"catch:\"), \" to capture one, and \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"try:\"), \" with\\n\", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"finally:\"), \" for cleanup. Each file is a library; \", mdx(\"inlineCode\", {\n    parentName: \"p\"\n  }, \"import .helpers\"), \" imports a sibling\\nfile. Continue with \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/language/exceptions\"\n  }, \"exceptions\"), \", \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/language/imports\"\n  }, \"imports\"), \",\\nand the \", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/language/package/pkgguide\"\n  }, \"package quick start\"), \".\"), mdx(\"p\", null, \"For additional examples of call grouping, string interpolation, defaults, and\\nblock control flow, expand the example collections in\\n\", mdx(\"a\", {\n    parentName: \"p\",\n    \"href\": \"/language/toitversus\"\n  }, \"Toit for programmers\"), \".\"));\n}\n;\nMDXContent.isMDXComponent = true;","tableOfContents":{"items":[{"url":"#toit-for-python-programmers","title":"Toit for Python programmers","items":[{"url":"#indentation-is-familiar-calls-are-different","title":"Indentation is familiar; calls are different","items":[{"url":"#variables-and-names","title":"Variables and names"},{"url":"#named-arguments","title":"Named arguments"}]},{"url":"#test-emptiness-explicitly","title":"Test emptiness explicitly"},{"url":"#integer-division-truncates-toward-zero","title":"Integer division truncates toward zero"},{"url":"#iteration-blocks-can-return-from-their-function","title":"Iteration blocks can return from their function"},{"url":"#declare-fields-in-the-class","title":"Declare fields in the class"},{"url":"#type-annotations-check-values","title":"Type annotations check values"},{"url":"#ordinary-functions-can-wait","title":"Ordinary functions can wait"},{"url":"#exceptions-and-imports-have-their-own-syntax","title":"Exceptions and imports have their own syntax"}]}]}}},"pageContext":{"title":"For Python programmers","id":"e7b8f0a9-4692-53ed-9c43-dfe116ce616b"}},
    "staticQueryHashes": ["2197327828"]}