Skip to content
Course map | Lesson 3 of 5

Data Structures · 4.3

Structs

All lessons are open — jump whenever you need.

struct Person {
    name: str,
    age: int,
}

impl Person {
    fn new(name: str, age: int) -> Person {
        return Person { name, age }
    }

    fn greet(self) -> str {
        return "Hello, I'm {self.name}!"
    }
}

let p = Person.new("Alice", 30)
print(p.greet())

Goal: Create a struct Circle with a radius field and an area method (pi ~ 3.14). Test with radius = 5, output: 78.5.

lesson-4-3.zolo
Program output

Run the code to see the output

Global index

Find your way through Zolo

Try an idea

Start here

9 results

9 results

enespt-br