go-variables


tags:

  • ready
  • online
  • reviewed
  • go
  • summary
  • informatic
  • variables

variables

Contents

__Roadmap info from [ roadmap website ] (https://roadmap.sh/golang/go-basics/variables) __

Variables in Go

Variable is the name given to a memory location to store a value of a specific [ type ] (https://golangbot.com/types/).Go provides multiple ways to declare and use variables.Visit the following resources to learn more:

  • @official@Go Variables

    Go Variable Naming Rules

    A variable can have a short name (like x and y) or a more descriptive name (age, price, carname, etc.).

    Go variable naming rules:

    • A variable name must start with a letter or an underscore character (_)
    • A variable name cannot start with a digit
    • A variable name can only contain alpha-numeric characters and underscores (a-z, A-Z, 0-9, and _ )
    • Variable names are case-sensitive (age, Age and AGE are three different variables)
    • There is no limit on the length of the variable name
    • A variable name cannot contain spaces
    • The variable name cannot be any Go keywords

    Difference Between var and :=

    There are some small differences between the var and :=:

    var:=
    Can be used inside and outside of functionsCan only be used inside functions
    Variable declaration and value assignment can be done separatelyVariable declaration and value assignment cannot be done separately