CodeBlanks Logo Icon CodeBlanks

bool and string

Learn boolean and text types.

bool and string

A bool can only be true or false; it is the result of comparisons. A string is text inside double quotes.

aktif := true
ad := "Ada"
yetiskin := 20 >= 18   // true
fmt.Println(aktif, ad, yetiskin)

Logical operators: && (and), || (or), ! (not).

String operations

Strings are joined with + and their byte length is taken with len. Backticks (`...`) write a raw string: \n inside isn't treated as an escape, and it can span several lines.

selam := "Merhaba " + "Go"
fmt.Println(selam, len(selam))  // Merhaba Go 10
yol := `C:\dosyalar\yeni`

Strings in Go are immutable; joining always produces a new string.

Practice Adult check

Declare ad := "Ada" and yas := 20. Compute yetiskin := yas >= 18 and print fmt.Println(ad + " yetişkin:", yetiskin).

Starter code

main.go
package main

import "fmt"

func main() {
    // buraya yaz
}

Sample solution

main.go
package main

import "fmt"

func main() {
    ad := "Ada"
    yas := 20
    yetiskin := yas >= 18
    fmt.Println(ad+" yetişkin:", yetiskin)
}

Expected output

Ada yetişkin: true

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What is the result of <code>true &amp;&amp; !false</code>?

  • false
  • An error
  • 1
  • true Correct answer

Explanation: !false becomes true; true && true gives true.

2 The and operator

Question
girisYapabilir := kayitli ____ sifreDogru
Answer
girisYapabilir := kayitli && sifreDogru

Explanation: && requires both conditions to be true.

3 Expression and result

Term Meaning
5 > 3 true
!true false
"a" + "b" "ab"
len("Go") 2

All lessons in Beginner