fmt

path: courses/go-course/fmt.md

- **fileName**: fmt
- **Created on**: 2024-08-23 19:33:05

starting go course : -

fmt library is library using for print string number boolean any thing in screen

package main
import "fmt"
func main() {
    fmt.Println("welcome from yossef")
    return
}
#!/usr/bin/bash
go build main.go ## execuate file binary main and run the main file 
./main

- now fmt.Println using for print new text in new line and there is alot of method for printing in fmt the commen one to use it Println

fmt Package Print Methods in Go

Method Description Example Output
fmt.Print() Prints the provided arguments as-is to the standard output. go<br>fmt.Print("Hello, ")<br>fmt.Print("world!") Hello, world!
fmt.Println() Similar to fmt.Print(), but adds a newline (\n) at the end of the output. go<br>fmt.Println("Hello,")<br>fmt.Println("world!") Hello,
world!
fmt.Printf() Allows formatted string output with format specifiers. go<br>name := "Alice"<br>age := 25<br>fmt.Printf("Name: %s, Age: %d\n", name, age) Name: Alice, Age: 25
fmt.Sprint() Returns a formatted string without printing it. go<br>greeting := fmt.Sprint("Hello, ", "world!")<br>fmt.Println(greeting) Hello, world!
fmt.Sprintln() Similar to fmt.Sprint(), but adds a newline (\n) at the end of the string. go<br>greeting := fmt.Sprintln("Hello, world!")<br>fmt.Println(greeting) Hello, world!
fmt.Sprintf() Similar to fmt.Printf(), but returns the formatted string instead of printing it. go<br>name := "Alice"<br>age := 25<br>formattedString := fmt.Sprintf("Name: %s, Age: %d", name, age)<br>fmt.Println(formattedString) Name: Alice, Age: 25
fmt.Fprint() Similar to fmt.Print(), but prints to a specified io.Writer instead of the standard output. go<br>fmt.Fprint(os.Stdout, "Hello, world!") Hello, world!
fmt.Fprintln() Similar to fmt.Println(), but prints to a specified io.Writer and adds a newline at the end. go<br>fmt.Fprintln(os.Stdout, "Hello, world!") Hello, world!
fmt.Fprintf() Similar to fmt.Printf(), but prints to a specified io.Writer instead of the standard output. go<br>name := "Alice"<br>age := 25<br>fmt.Fprintf(os.Stdout, "Name: %s, Age: %d\n", name, age) Name: Alice, Age: 25

for string formated

string-format-go.md

continue:string-format-go.md
before:[[]]