Module 2: Basics (Variables, Types & Functions)
Variables (ကိန်းရှင်များ)
Section titled “Variables (ကိန်းရှင်များ)”Go မှာ Variable ကြေညာဖို့ နည်းလမ်း (၂) မျိုး ရှိပါတယ်။
၁. var Keyword အသုံးပြုခြင်း
Section titled “၁. var Keyword အသုံးပြုခြင်း”var name string = "Mg Mg"var age int = 20var isStudent bool = trueType ကို မထည့်ဘဲလည်း ရေးလို့ရပါတယ်။ Go က အလိုအလျောက် သိပါတယ်။
var city = "Yangon" // string လို့ အလိုအလျောက် သတ်မှတ်ပေးတယ်၂. Short Variable Declaration (:=)
Section titled “၂. Short Variable Declaration (:=)”Function တွေထဲမှာဆိုရင် := ကို သုံးပြီး အလွယ်တကူ ကြေညာနိုင်ပါတယ်။ (အသုံးအများဆုံး နည်းလမ်းပါ)
func main() { country := "Myanmar" population := 54000000
fmt.Println(country, population)}Basic Data Types
Section titled “Basic Data Types”Go မှာ အဓိက Data Types တွေကတော့-
- String: စာသားများ (
"Hello") - Integer: ကိန်းပြည့်များ (
int,int8,int16,int32,int64) - Float: ဒသမကိန်းများ (
float32,float64) - Boolean: မှန်/မှား (
true,false)
Functions (လုပ်ဆောင်ချက်များ)
Section titled “Functions (လုပ်ဆောင်ချက်များ)”Function တွေကို func keyword နဲ့ တည်ဆောက်ပါတယ်။
func add(x int, y int) int { return x + y}
func main() { result := add(5, 10) fmt.Println(result) // 15}Multiple Return Values (တန်ဖိုး အများကြီး ပြန်ပေးခြင်း)
Section titled “Multiple Return Values (တန်ဖိုး အများကြီး ပြန်ပေးခြင်း)”Go ရဲ့ ထူးခြားချက်တစ်ခုက Function တစ်ခုကနေ တန်ဖိုး တစ်ခုထက်မက ပြန်ပေး (Return) နိုင်တာပါ။
func swap(a string, b string) (string, string) { return b, a}
func main() { first, second := swap("Hello", "World") fmt.Println(first, second) // World Hello}