Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,2 @@
fmt.Println('a') // prints "97"
fmt.Println('π') // prints "960"

View file

@ -0,0 +1,12 @@
package main
import (
"fmt"
)
func main() {
// Given a character value in your language, print its code
fmt.Printf("%d\n", 'A') // prt 65
// Given a code, print out the corresponding character.
fmt.Printf("%c\n", 65) // prt A
}

View file

@ -0,0 +1,21 @@
package main
import "fmt"
func main() {
// yes, there is more concise syntax, but this makes
// the data types very clear.
var b byte = 'a'
var r rune = 'π'
var s string = "aπ"
fmt.Println(b, r, s)
fmt.Println("string cast to []rune:", []rune(s))
// A range loop over a string gives runes, not bytes
fmt.Print(" string range loop: ")
for _, c := range s {
fmt.Print(c, " ") // c is type rune
}
// We can also print the bytes of a string without an explicit loop
fmt.Printf("\n string bytes: % #x\n", s)
}

View file

@ -0,0 +1,3 @@
b := byte(97)
r := rune(960)
fmt.Printf("%c %c\n%c %c\n", 97, 960, b, r)

View file

@ -0,0 +1,3 @@
fmt.Println(string(97)) // prints "a"
fmt.Println(string(960)) // prints "π"
fmt.Println(string([]rune{97, 960})) // prints "aπ"