Optional variable types are types that are allowed to contain a nil values:
nil
foo: int? = 10 foo = nil foo = 100
Optional types are denoted by a ?
?
We can safely unwrap an optional value, given that it exists, using !like this:
!
foo: str? = maybe_a_str() bar: str = foo!
Last updated 6 years ago