Maison > Article > développement back-end > Pourquoi est-ce que j'obtiens une erreur « plus d'un caractère dans un littéral runique » dans mon code Go ?
Syntax Error in Go Rune Literal
In the provided Go code snippet, an error prompts the "more than one character in rune literal" message. To rectify this issue, we need to understand the distinction between rune literals and string literals in Go.
Rune Literals vs. String Literals
In Go, single quotes, denoted as ', are reserved for rune literals, which represent UTF-8 characters. On the other hand, double quotes, denoted as ", are used for string literals, which are sequences of characters.
Modifying the Code
In your specific case, the error pertains to the line where you're printing the value of the variable a:
fmt.Println("%d is odd number", a)
Here, you've mistakenly used single quotes around the format specifier %d, which should be in double quotes to designate a string literal. The correct version:
fmt.Println("%d is odd number", a)
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!