Variables

지니🧸·2023년 8월 29일
0

Go

목록 보기
2/8

본 게시글은 Golang Tutorial for Beginners | Full Go Course을 학습하며 작성한 개인 노트입니다.

Variables

Variable: stores values

var conferenceName = "Go Conference"
fmt.Println("Welcome to", conferenceName, "booking application!")
  • camel case
  • declared variables must be used; otherwise error

Constants

variables whose values do not change

const num = 50
fmt.Println(num)

error if attempt to change constant values

Print formatted data

printf

fmt.Printf("Hello my name is %s", myName)
  • takes a template string that contains the text that needs to be formatted
  • variable to replace the template string is added

Sprintf

var varia = fmt.Sprintf("Hello my name is %v\n", name)

Another way to create variable

name := "hi"
  • you cannot declare constants with this syntax
  • cannot specifically define a type
profile
우당탕탕

0개의 댓글