Avatar ·

How to get a string character by index in Go? (Problem with runes and bytes)

Hello everyone! I'm new to Go and encountered an unexpected problem when working with strings. I need to get a character from a string by its index, as I'm used to doing in other languages (e.g., `str[i]` in Python or `charAt(i)` in Java). Here's my code: ```go package main import "fmt" func main() { str := "Привет, мир!" fmt.Println(str[0]) // Prints 208, not 'П' fmt.Println(string(str[0])) // Prints 'Ð', not 'П' } ``` I expected `str[0]` to return the first character 'П', but instead I get some strange numbers and characters. Why is this happening? How do I correctly get a character by index in Go? I tried using `string(str[0])`, but that doesn't work correctly either. It's especially strange that for English letters (e.g., "Hello") everything works fine, but