In Conversation with Go-Lang’s DataTypes | Part2

In case you are landing here directly, it’s suggested that you go and read through this for fundamentals.

Question: What are various variables and language constructs supported by Go-Lang ?

Answer: As with all programming languages you can store data in memory in Go, using variables. Go is a statically typed language. That means that each variable must be assigned to type and once assigned it can’t be changed. You can set types for each variable either explicitly, by naming the type in the variable declaration or implicitly, by allowing the compiler to infer the type based on a value that you initially assign. Go comes with a set of built-in data types. You can also define your own data types but these are the ones that are always available to you.

  • The first type is bool, for Boolean. This is a simple true, false value and the only two values that you can assign are true and false.
  • There are two floating types, float32 and float64. And, once again, the numeric values in the names indicate the number of bits used for storage and therefore, the range that’s available to you.

Question: How doe we declare the String variable ?

Answer: Following is an example of string data-type creation :-

Question: How doe we declare the Integer variable, What’s the default value of Integer and How do we see the Type of the declared variable ?

Answer: We have functions available in Go-Lang for performing the desired operations :

Question: Can Go, also infer the data-type on its own ? Do we always need to mention the corresponding data-types during variables-declaration ?

Answer: Yes, Go-Lang can definitely infer the data-types too.

Question: How can we receive Input from the Standard-Input ?

Answer: We can receive inputs from the Standard Input like as shown below using 2 packages :0

  • bufio

Note above that :-

  • That’s yet another way in Go-Lang to receive-in the values for the variables.

Question: What if we wanted to take in Input as Numerals or Floating point numbers through the Standard-Input ?

Answer: We have learnt following packages so far, the receiving inputs is concerned :-

  • We get the input from the console using the bufio packages, new reader function and a reader object and the OS.standard in object to get data specifically from what the user types in. These values always come to you as strings.

Now I need to evaluate that error object. The error will be nil if everything went fine.

Or if there was a parsing problem, it’ll come back as a non nil object which is being described as below :-

Question: Can we directly add the variables of even different-types ?

Answer: We can’t perform the addition :-

Question: How to perform the addition operations between two variables of even different-types ?

Answer: We need to convert the one to another variable, because Matching types are required in math operations.

Question: Is there a way in Go-Lang to round-off the floating point numbers to the nearest Integer automatically ?

Answer: Yes, there is MATH library available in Go-Lang :-

Note above that, the type for “3.7” has been automatically inferred, under the hoods.

Question: What all Operators are supported in the Go-Lang ?

Question: Can we declare multiple variables in a single line ?

Answer: Yes, that’s very much possible in Go-Lang :-

Question: What’s the way to get the result of addition of floating-numbers ?

Question: What’s yet another way of rounding-off to desired precision ?

Question: Can you show me yet another example of rounding-off operation ?

Question: Can you show me yet another example for performing rounding -operation and division-operation with numbers in Go-Lang ?

Question: How can we declare the time, using the time library available in Go-Lang ?

Question: What are other ways of formatting the time, in whatever user-desired format?

Question: How can we declare the particular timeStamp of past/future ?

Question: How can we exit the Program-execution, in case of any error ?

Question: Let’s construct the simple example of Addition-Calculator ?

Please clap now, if you scrolled till here.

References :-



Software Engineer for Big Data distributed systems

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store