DEV Community

V Sai Harsha
V Sai Harsha

Posted on • Edited on

1 1 1 1 1

Mojo cheat sheet

Today, Mojo SDK is officially launched by Modular Team. So, Today I going to make a cheat sheet for you!

Declaring a Mutable Variable

var x = 1
Enter fullscreen mode Exit fullscreen mode

Explicitly Typed Variable

var x: Int = 1
Enter fullscreen mode Exit fullscreen mode

Declaring an Immutable Variable

let x = 1
Enter fullscreen mode Exit fullscreen mode

Functions

fn greet():
    print("🔥🔥")
Enter fullscreen mode Exit fullscreen mode

Structs

struct MyPair:
    var first: Int
    var second: Int

    fn __init__(inout self, first: Int, second: Int):
        self.first = first
        self.second = second

    fn dump(self):
        print(self.first, self.second)
Enter fullscreen mode Exit fullscreen mode

Integrate with Python

from python import Python

let np = Python.import_module("numpy")

ar = np.arange(15).reshape(3, 5)
print(ar)
print(ar.shape)
Enter fullscreen mode Exit fullscreen mode

This cheat sheet covers the basics of Mojo and I do know this is short but Mojo has a lot of complex concepts related to memory management, copyinit, ownership and borrow checking. As of today, Mojo is early in development and released recently. So, I like this Mutli-threaded language and its memory management is similar to Rust. It does not many features of Python like anynomynous functions with lambda.

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay