Go की मूल बातें

Hello World in Go: Structure of a Program

Write your first Go program and see what each part does: package main, import and func main.

  • शुरुआती
  • 2 मिनट में पढ़ें
  • 1 चलाने योग्य उदाहरण
आप क्या सीखेंगे
  • package main and func main
  • Importing fmt
  • Printing with fmt.Println
From source to output
  1. 1main.goYou write the code
  2. 2go runGo compiles and starts it
  3. 3main()The program starts in main
  4. 4Hello, Go!The text appears

How a Go program runs

Every Go file starts with a package name. A program that you can run lives in package main and starts in the function main. import brings in other packages, such as fmt for printing.

fmt.Println prints its arguments and ends the line. Names that start with a capital letter, such as Println, are the ones a package makes available to other packages.

मुख्य बातें

  1. A runnable program lives in package main.
  2. It starts in func main.
  3. fmt.Println prints a line of text.

चलने योग्य Go उदाहरण

Go
कोड चलाएँ →
main.go
package main

import "fmt"

func main() {
	fmt.Println("Hello, Go!")
}
इस उदाहरण के लिए Run बटन बनाएँ कोड चलाने का परिणाम
Hello, Go!

अभ्यास

उदाहरण को ऑनलाइन कंपाइलर में खोलें, कोई मान बदलें या एक पंक्ति जोड़ें, और चलाने से पहले आउटपुट का अनुमान लगाएँ। फिर कोड में जान-बूझकर गलती करें और कंपाइलर का संदेश पढ़ें।

यह पाठ पूरा कर लिया?

अपनी प्रगति ट्रैक करने के लिए इसे सीखा हुआ मार्क करें।

अगला: Variables and Constants →

चैलेंज से अभ्यास करें

इस पाठ में सीखी बात से एक असली समस्या हल करें। हर चैलेंज ब्राउज़र में चलता है, तुरंत टेस्ट और AI रिव्यू के साथ।

सभी चैलेंज