2. Values, variables, and types¶
This chapter introduces basic values and types.
If you get stuck on terminology, see: Glossary.
Basic values¶
Common built-in types:
int(ordinary integers)float(ordinary binary floating point)bool(true/false)str(strings)
Incan also has exact numeric types for data and Rust interop boundaries, such as i32, u64, usize, f32, and f64, plus fixed-scale decimal types such as decimal[10, 2]. You usually do not need those in beginner code, but they matter when another system owns the width or precision.
For the full rules, see Choosing numeric types, Numeric semantics, and Why numeric types work this way.
Variables¶
Assign a value to a name:
Coming from Python?
Incan supports Python-style f-strings for string interpolation:
name = "Incan"
println(f"hello, {name}")
For more examples and formatting details, see: Strings.
def main() -> None:
name = "Incan"
answer = 42
println(f"{name}: {answer}")
Function arguments and return types¶
Incan uses type annotations on function arguments and return types:
def add(a: int, b: int) -> int:
return a + b
Try it¶
- Create a
str,int,float, andboolvariable and print them. - Use an f-string with multiple
{...}interpolations. - Call
add(10, 32)and print the result.
One possible solution
def add(a: int, b: int) -> int:
return a + b
def main() -> None:
name = "Incan"
count = 3
ratio = 0.5
enabled = true
println(f"name={name} count={count} ratio={ratio} enabled={enabled}")
println(f"add={add(10, 32)}")