
इस ब्लॉग में आप सीखेंगे:
- Mojo में Variables और Constants कैसे बनाएँ
- Data types कौन-कौन से होते हैं
- Syntax और Examples
Variable Declaration
Mojo में var
keyword से variable define करते हैं।
var age: Int = 25 var name: String = "Rahul" var isActive: Bool = True
Constants with let
जो value change नहीं होगी, उसके लिए let
keyword use करें।
let PI: Float = 3.1415 let country: String = "India"
Mojo Types
Int
: पूरा numberFloat
: दशमलव numberBool
: True/FalseString
: Text
var count: Int = 10 var price: Float = 99.99 var isAvailable: Bool = False var message: String = "Hello Mojo"
Type Annotations जरूरी हैं
Mojo में type देना जरूरी है:
var x: Int = 10 सही var x = 10 गलत
Sample Mojo Program
fn main(): var age: Int = 20 let country: String = "India" var price: Float = 99.5 var isMember: Bool = True print("Age:", age) print("Country:", country) print("Price:", price) print("Is Member:", isMember)
Output:
Age: 20 Country: India Price: 99.5 Is Member: True
Tips:
var
: changeable valueslet
: constant values- Indentation Python जैसा
अगले ब्लॉग में:
Blog 4: Mojo Functions – Define, Parameters, Return Types