StarknetAstro

StarknetAstro

07_Cairo Tuple (Tuple) In this text, the term "Tuple" refers to a data structure in the programming language Cairo.

Tuple in Cairo#

The version of the Cairo compiler used in this article is 2.0.0-rc0. Since Cairo is being updated rapidly, the syntax may vary slightly in different versions, and the content of the article will be updated to a stable version in the future.

A tuple is an interesting type that is present in many programming languages. It allows different types to be combined together to form a collection. Once declared, the number of types it can hold cannot be increased or decreased, and the types inside it cannot be changed.

Basic Usage#

use debug::PrintTrait;

fn main() {
    let tup: (u32, u64, bool) = (10, 20, true);
    let (x, y, z) = tup;
    x.print();
}

In the above code, a tuple is created that contains three types: u32, u64, bool. The line let (x, y, z) = tup; demonstrates how the elements of the tuple can be extracted.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.