2. Go - Basic Format Printing

Example Code:

package main

import "fmt"

func test(a int, b string, c bool, d float64) (int, string, bool, float64) {
    x := a + 5
    y := "world"
    z := true
    x1 := 5.06
    return x, y, z, x1
}

func main() {

        xstring := "STRING"
        fmt.Println(len(xstring))
        fmt.Println(xstring[0])
        fmt.Println(xstring+"VALUE")

    answer, a, b, c := test(50, "hello", false, 3.2)
    fmt.Printf("Number: %d, String: %s, Bool:%t, Float:%g", answer, a, b, c)
}


Strings can be declared with double quotes:

var name = "hello"


Strings can be declared with back quotes:

Everything between the backquotes will be a string. Don't have to use escapes, they print as is.

var name = `"hello" world`


Types of Printing:

Print Group: Printing to stdout (standard output)

Print() // prints without a newline

Println() // prints and adds a newline

Printf() // prints with special formatting or in different types


Sprint Group: Allows print and attach the string to be used in a variable. String printing.

Sprint() 

Sprintln()

Sprintf()


Fprint Group: printing to a file or web server's response

Fprint()

Fprintln()

Fprintf()


Comments

Popular posts from this blog

2. FreeCodeCamp - Dynamic Programming - Learn to Solve Algorithmic Problems & Coding Challenges

20. Data Analytics - Analyze Data to Answer Questions - Week 1

3. Algorithms - Selection Sort