Giter Club home page Giter Club logo

go's Introduction

Go

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.

Go was designed at Google in 2007 to improve programming productivity in an era of multicore, networked machines and large codebases.

Hello world

package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
} 

Package

Every Go program is made up of packages.

A Go program starts running in the main package.

This is why we need to declare our code as the main package -- to make it run and create the output:

Import

Apart from main, Go has many packages that can be imported and used in the code to accomplish different tasks.

One of the most popular packages is "fmt", which stands for format, and provides input and output functionality.

To import a package, we use the import statement:

Variables

Variables are used to store values.

In Go, the var keyword is used to declare variables.

	var x int

The code above declares a variable named i of type int. int stands for integer and represents whole numbers.

We can assign the variable a value and output it:

	var x int = 8

You can also declare multiple variables on one line and assign values to them:

	var i,j int = 87,89

If you assign a value to the variable, you can omit the type declaration, as Go will automatically take the type of the value assigned:

	var i,name = 89,"Go"

Go supports short variable declaration using :=.

	x := 89
	name := "Emdadul"

Data Type

Let's see what other common types Go supports.

  • float32 - a single-precision floating point value.
  • float64 - a double-precision floating point value.
  • string - a text value.
  • bool - Boolean true or false.
package main

import "fmt"

func main() {
  var x int = 76742
  var y float32 = 1.3877
  var name string = "Emdadul"
  var flag bool = true

  fmt.Println(name)
  fmt.Println(x)
  fmt.Println(y)
  fmt.Println(flag)
}

Arithmetic Operator

Go supports all of the common arithmetic operators. (+ - * / %)

package main

import "fmt"

func main() {

  x := 45
  y := 7
  
  //Addition
  add := x+y
  fmt.Println(add)
  
  //Subtraction
  sub := x-y
  fmt.Println(sub)
  
  //Multipication
  mul := x*y
  fmt.Println(mul)
  
  //Division 
  div := x/y
  fmt.Println(div)
      
  // Modulus, results in the remainder of the division
  rem := x % y
  fmt.Println(rem) 
}

go's People

Contributors

mdadul avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.