Introduction to Maps
Part of the Fundamentals section of Coddy's GO journey — lesson 84 of 109.
Maps in Go are key-value pairs, similar to dictionaries in other languages. They let you store and retrieve values using unique keys.
Create a map that associates string names with integer ages:
ages := map[string]int{
"Alice": 25,
"Bob": 30,
}Access a value using its key:
aliceAge := ages["Alice"]
fmt.Println(aliceAge)The output will be:
25Add a new key-value pair:
ages["Charlie"] = 22Cheat sheet
Maps in Go are key-value pairs that store and retrieve values using unique keys.
Create a map:
ages := map[string]int{
"Alice": 25,
"Bob": 30,
}Access a value using its key:
aliceAge := ages["Alice"]Add a new key-value pair:
ages["Charlie"] = 22Try it yourself
This lesson doesn't include a code challenge.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Comparison & Logical Operators
Comparison Operators - Part 1Comparison Operators - Part 2Logical AND OperatorLogical OR OperatorLogical NOT OperatorOperator Precedence BasicsRecap - Making Comparisons7Control Flow: Loops
What The `for` Loop ExplainedFor Loop - BasicFor Loop - Condition OnlyThe `break` KeywordThe `continue` KeywordNested LoopsRecap - Repeating Actions2Variables and Basic Data Types
What is a variableType Inference with `:=`Integers (int)Floating-Point NumbersBooleansStringsZero ValuesConstantsNaming ConventionsRecap - Variables and Types5Basic Input/Output
Formatted OutputFormat VerbsPrinting TypesGetting Basic User InputRecap - Input and Output8Functions
Understanding FunctionsDeclaring a FunctionCalling FunctionsFunction ParametersReturning a Single ValueReturning Multiple ValuesNamed Return ValuesFunction Scope BasicsRecap - Creating Reusable Code3Basic Operators
Arithmetic OperatorsDivision OperatorThe Modulo OperatorAssignment OperatorAugmented Assignment OperatorsIncrement and DecrementRecap - Calculations6Control Flow: Conditionals
The `if` StatementThe `else` KeywordThe `else if` KeywordVariable Shadowing in `if`Initializing VariablesThe `switch` StatementSwitch with ExpressionsSwitch without ExpressionThe `fallthrough` KeywordRecap - Making Decisions