Défi : Bases des Variables
Tâche
Compléter le code suivant afin que myVar1 et myVar2 soient tous deux déclarés et initialisés avec succès.
index.go
123456789package main import "fmt" func main() { ___ myVar1 = 1 myVar2 __ 2 fmt.Println("The value of myVar1 is", myVar1) fmt.Println("The value of myVar2 is", myVar2) }
- Utiliser
varpour déclarer une variable. - Utiliser
:=pour une déclaration et initialisation courte de variable. - Chaque variable nécessite un nom et une valeur.
package main
import "fmt"
func main() {
var myVar1 = 1
myVar2 := 2
fmt.Println("The value of myVar1 is", myVar1)
fmt.Println("The value of myVar2 is", myVar2)
}
Tout était clair ?
Merci pour vos commentaires !
Section 1. Chapitre 10
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion
Suggested prompts:
Can you explain the difference between using `var` and `:=` in Go?
What happens if I try to use `:=` outside of a function in Go?
Can you show me how to declare multiple variables at once in Go?
Awesome!
Completion rate improved to 1.96
Défi : Bases des Variables
Glissez pour afficher le menu
Tâche
Compléter le code suivant afin que myVar1 et myVar2 soient tous deux déclarés et initialisés avec succès.
index.go
123456789package main import "fmt" func main() { ___ myVar1 = 1 myVar2 __ 2 fmt.Println("The value of myVar1 is", myVar1) fmt.Println("The value of myVar2 is", myVar2) }
- Utiliser
varpour déclarer une variable. - Utiliser
:=pour une déclaration et initialisation courte de variable. - Chaque variable nécessite un nom et une valeur.
package main
import "fmt"
func main() {
var myVar1 = 1
myVar2 := 2
fmt.Println("The value of myVar1 is", myVar1)
fmt.Println("The value of myVar2 is", myVar2)
}
Tout était clair ?
Merci pour vos commentaires !
Section 1. Chapitre 10