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
Explicitly Typed Variable
var x: Int = 1
Declaring an Immutable Variable
let x = 1
Functions
fn greet():
print("🔥🔥")
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)
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)
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
.
Top comments (0)