User Input (fmt.Scan, bufio, os.Args, strconv) - Go Tutorial for Beginners #5
13views
005:43
T
Taught by Celeste AI - AI Coding Coach
View on YouTubeDescription
Learn how to read user input in Go!
In this lesson, you will learn:
✅ Basic input with fmt.Scan and fmt.Scanln
✅ Reading full lines with bufio.Reader and bufio.Scanner
✅ Accessing command-line arguments with os.Args
✅ Parsing strings to numbers with strconv (Atoi, ParseFloat, ParseBool)
🕐 Timestamps:
0:00 - Introduction
0:24 - Basic Input with fmt.Scan
1:20 - Line Input with bufio
2:17 - Command Line Arguments
3:11 - Parsing with strconv
4:17 - Recap
4:47 - End
💻 Code from this lesson:
// Basic input with fmt.Scan
var name string
fmt.Print("Enter your name: ")
fmt.Scanln(&name)
// Reading lines with bufio
reader := bufio.NewReader(os.Stdin)
line, _ := reader.ReadString('\n')
// Command-line arguments
fmt.Println(os.Args[0]) // program name
fmt.Println(os.Args[1]) // first argument
🔗 Previous: Lesson 4 - Numbers & Math
🔗 Next: Lesson 6 - Control Flow: if/else