Sam  Son

Sam Son


Data Types in Go


Data types specify the kinds of values that particular variables will store when you are writing a program. The data type also determines what operations can be performed on the data.

In this article, we will go over the important data types native to Go. This is not an exhaustive investigation of data types, but will help you become familiar with what options you have available to you in Go. Understanding some basic data types will enable you to write clearer code that performs efficiently.


One way to think about data types is to consider the different types of data that we use in the real world. An example of data in the real world are numbers: we may use whole numbers (0, 1, 2, …), integers (…, -1, 0, 1, …), and irrational numbers (π), for example.

Usually, in math, we can combine numbers from different types, and get some kind of an answer. We may want to add 5 to π, for example:

5 + π

We can either keep the equation as the answer to account for the irrational number, or round π to a number with an abbreviated number of decimal places, and then add the numbers together:

5 + π = 5 + 3.14 = 8.14 

But, if we start to try to evaluate numbers with another data type, such as words, things start to make less sense. How would we solve for the following equation?

shark + 8

For computers, each data type is quite different—like words and numbers. As a result we have to be careful about how we use varying data types to assign values and how we manipulate them through operations.


Like in math, integers in computer programming are whole numbers that can be positive, negative, or 0 (…, -1, 0, 1, …). In Go, an integer is known as an int. As with other programming languages, you should not use commas in numbers of four digits or more, so when you write 1,000 in your program, write it as 1000.

We can print out an integer in a simple way like this:


Or, we can declare a variable, which in this case is a symbol of the number we are using or manipulating, like so:

var absoluteZero int = -459

We can do math with integers in Go, too. In the following code block, we will use the := assignment operator to declare and instantiate the variable sum:

sum := 116 - 68

As the output shows, the mathematical operator - subtracted the integer 68 from 116, resulting in 48. You'll learn more about variable declaration in the Declaring Data Types for Variables section.

Integers can be used in many ways within Go programs. As you continue to learn about Go, you'll have a lot of opportunities to work with integers and build upon your knowledge of this data type.

Floating-Point Numbers

floating-point number or a float is used to represent real numbers that cannot be expressed as integers. Real numbers include all rational and irrational numbers, and because of this, floating-point numbers can contain a fractional part, such as 9.0 or -116.42. For the purposes of thinking of a float in a Go program, it is a number that contains a decimal point.

Like we did with integers, we can print out a floating-point number in a simple way like this:


We can also declare a variable that stands in for a float, like so:

absoluteZero := -459.67

Just like with integers, we can do math with floats in Go, too:

var sum = 564.0 + 365.24

With integers and floating-point numbers, it is important to keep in mind that 3 ≠ 3.0, as 3 refers to an integer while 3.0 refers to a float.

Sizes of Numeric Types

In addition to the distinction between integers and floats, Go has two types of numeric data that are distinguished by the static or dynamic nature of their sizes. The first type is an architecture-independenttype, which means that the size of the data in bits does not change, regardless of the machine that the code is running on.

Most system architectures today are either 32 bit or 64 bit. For instance, you may be developing for a modern Windows laptop, on which the operating system runs on a 64-bit architecture. However, if you are developing for a device like a fitness watch, you may be working with a 32-bit architecture. If you use an architecture-independent type like int32, regardless of the architecture you compile for, the type will have a constant size.

The second type is an implementation-specific type. In this type, the bit size can vary based on the architecture the program is built on. For instance, if we use the int type, when Go compiles for a 32-bit architecture, the size of the data type will be 32 bits. If the program is compiled for a 64-bit architecture, the variable will be 64 bits in size.

In addition to data types having different sizes, types like integers also come in two basic types: signedand unsigned. An int8 is a signed integer, and can have a value from -128 to 127. A uint8 is an unsigned integer, and can only have a positive value of 0 to 255.

The ranges are based on the bit size. For binary data, 8 bits can represent a total of 256 different values. Because an int type needs to support both positive and negative values, an 8-bit integer (int8) will have a range of -128 to 127, for a total of 256 unique possible values.

Go has the following architecture-independent integer types:

uint8       unsigned  8-bit integers (0 to 255)
uint16      unsigned 16-bit integers (0 to 65535)
uint32      unsigned 32-bit integers (0 to 4294967295)
uint64      unsigned 64-bit integers (0 to 18446744073709551615)
int8        signed  8-bit integers (-128 to 127)
int16       signed 16-bit integers (-32768 to 32767)
int32       signed 32-bit integers (-2147483648 to 2147483647)
int64       signed 64-bit integers (-9223372036854775808 to 9223372036854775807)

Floats and complex numbers also come in varying sizes:

float32     IEEE-754 32-bit floating-point numbers
float64     IEEE-754 64-bit floating-point numbers
complex64   complex numbers with float32 real and imaginary parts
complex128  complex numbers with float64 real and imaginary parts

There are also a couple of alias number types, which assign useful names to specific data types:

byte        alias for uint8
rune        alias for int32

The purpose of the byte alias is to make it clear when your program is using bytes as a common computing measurement in character string elements, as opposed to small integers unrelated to the byte data measurement. Even though byte and uint8 are identical once the program is compiled, byte is often used to represent character data in numeric form, whereas uint8 is intended to be a number in your program.

The rune alias is a bit different. Where byte and uint8 are exactly the same data, a rune can be a single byte or four bytes, a range determined by int32. A rune is used to represent a Unicode character, whereas only ASCII characters can be represented solely by an int32 data type.

In addition, Go has the following implementation-specific types:

uint     unsigned, either 32 or 64 bits
int      signed, either 32 or 64 bits
uintptr  unsigned integer large enough to store the uninterpreted bits of a pointer value 

Implementation-specific types will have their size defined by the architecture the program is compiled for.

Picking Numeric Data Types

Picking the correct size usually has more to do with performance for the target architecture you are programming for than the size of the data you are working with. However, without needing to know the specific ramifications of performance for your program, you can follow some of these basic guidelines when first starting out.

As discussed earlier in this article, there are architecture-independent types, and implementation-specific types. For integer data, it's common in Go to use the implementation types like int or uint instead of int64 or uint64. This will typically result in the fastest processing speed for your target architecture. For instance, if you use an int64 and compile to a 32-bit architecture, it will take at least twice as much time to process those values as it takes additional CPU cycles to move the data across the architecture. If you used an int instead, the program would define it as a 32-bit size for a 32-bit architecture, and would be significantly faster to process.

If you know you won't exceed a specific size range, then picking an architecture-independent type can both increase speed and decrease memory usage. For example, if you know your data won't exceed the value of 100, and will only be a positive number, then choosing a uint8 would make your program more efficient as it will require less memory.

Now that we have looked at some of the possible ranges for numeric data types, let's look at what will happen if we exceed those ranges in our program.

Overflow vs. Wraparound

Go has the potential to both overflow a number and wraparound a number when you try to store a value larger than the data type was designed to store, depending on if the value is calculated at compile time or at runtime. A compile time error happens when the program finds an error as it tries to build the program. A runtime error happens after the program is compiled, while it is actually executing.

In the following example, we set maxUint32 to its maximum value:

package main

import “fmt”

func main() {
var maxUint32 uint32 = 4294967295 // Max uint32 size

It will compile and run with the following result:


If we add 1 to the value at runtime, it will wraparound to 0:


On the other hand, let’s change the program to add 1 to the variable when we assign it, before compile time:

package main

import “fmt”

func main() {
var maxUint32 uint32 = 4294967295 + 1


At compile time, if the compiler can determine a value will be too large to hold in the data type specified, it will throw an overflow error. This means that the value calculated is too large for the data type you specified.

Because the compiler can determine it will overflow the value, it will now throw an error:

prog.go:6:36: constant 4294967296 overflows uint32

Understanding the boundaries of your data will help you avoid potential bugs in your program in the future.

Now that we have covered numeric types, let’s look at how to store boolean values.


The boolean data type can be one of two values, either true or false, and is defined as bool when declaring it as a data type. Booleans are used to represent the truth values that are associated with the logic branch of mathematics, which informs algorithms in computer science.

The values true and false will always be with a lowercase t and f respectively, as they are pre-declared identifiers in Go.

Many operations in math give us answers that evaluate to either true or false:

greater than
500 > 100 true
1 > 5 false
less than
200 < 400 true
4 < 2 false
5 = 5 true
500 = 400 false

Like with numbers, we can store a boolean value in a variable:

myBool := 5 > 8

We can then print the boolean value with a call to the fmt.Println() function:


Since 5 is not greater than 8, we will receive the following output:


As you write more programs in Go, you will become more familiar with how booleans work and how different functions and operations evaluating to either true or false can change the course of the program.


A string is a sequence of one or more characters (letters, numbers, symbols) that can be either a constant or a variable. Strings exist within either back quotes </code>&nbsp;or double quotes&nbsp;<code>"</code>&nbsp;in Go and have different characteristics depending on which quotes you use.</p><p>If you use the back quotes, you are creating a&nbsp;<em>raw</em>&nbsp;string literal. If you use the double quotes, you are creating an&nbsp;<em>interpreted</em>&nbsp;string literal.</p><h3>Raw String Literals</h3><p>Raw string literals are character sequences between back quotes, often called back ticks. Within the quotes, any character will appear just as it is displayed between the back quotes, except for the back quote character itself.</p><pre class="ql-syntax" spellcheck="false">a := Say “hello” to Go!fmt.Println(a) Output Say "hello" to Go! </pre><p>Usually, backslashes are used to represent special characters in strings. For example, in an interpreted string,&nbsp;<code>\n</code>&nbsp;would represent a new line in a string. However, backslashes have no special meaning inside of raw string literals:</p><pre class="ql-syntax" spellcheck="false">a :=Say “hello” to Go!\nfmt.Println(a) </pre><p>Because the backslash has no special meaning in a string literal, it will actually print out the value of&nbsp;<code>\n</code>instead of making a new line:</p><pre class="ql-syntax" spellcheck="false">Output Say "hello" to Go!\n </pre><p>Raw string literals may also be used to create multiline strings:</p><pre class="ql-syntax" spellcheck="false">a :=This string is on
multiple lines
within a single back
quote on either side.`

This string is on
multiple lines
within a single back
quote on either side.

In the preceding code blocks, the new lines were carried over literally from input to output.

Interpreted String Literals

Interpreted string literals are character sequences between double quotes, as in “bar”. Within the quotes, any character may appear except newline and unescaped double quotes. To show double quotes in an interpreted string, you can use the backslash as an escape character, like so:

a := “Say “hello” to Go!”
Say “hello” to Go!

You will almost always use interpreted string literals because they allow for escape characters within them. For more on working with strings, check out An Introduction to Working with Strings in Go.

Strings with UTF-8 Characters

UTF-8 is an encoding scheme used to encode variable width characters into one to four bytes. Go supports UTF-8 characters out of the box, without any special setup, libaries, or packages. Roman characters such as the letter A can be represented by an ASCII value such as the number 65. However, with special characters such as an international character of , UTF-8 would be required. Go uses the rune alias type for UTF-8 data.

a := “Hello, 世界”

You can use the range keyword in a for loop to index through any string in Go, even a UTF-8 string. forloops and range will be covered in more depth later in the series; for now, it’s important to know that we can use this to count the bytes in a given string:

package main

import “fmt”

func main() {
a := “Hello, 世界”
for i, c := range a {
fmt.Printf(“%d: %s\n”, i, string©)
fmt.Println("length of ‘Hello, 世界’: ", len(a))

In the above code block, we declared the variable a and assigned the value of Hello, 世界 to it. The text assigned has UTF-8 characters in it.

We then used a standard for loop as well as the range keyword. In Go, the range keyword will index through a string returning one character at a time, as well as the byte index the character is at in the string.

Using the fmt.Printf function, we provided a format string of %d: %s\n%d is the print verb for a digit (in this case an integer), and %s is the print verb for a string. We then provided the values of i, which is the current index of the for loop, and c, which is the current character in the for loop.

Finally, we printed the entire length of the variable a by using the builtin len function.

Earlier, we mentioned that a rune is an alias for int32 and can be made up of one to four bytes. The character takes three bytes to define and the index moves accordingly when ranging through the UTF-8 string. This is the reason that i is not sequential when it is printed out.

0: H
1: e
2: l
3: l
4: o
5: ,
7: 世
10: 界
length of ‘Hello, 世界’: 13

As you can see, the length is longer than the number of times it took to range over the string.

You won’t always be working with UTF-8 strings, but when you are, you’ll now understand why they are runes and not a single int32.

Declaring Data Types for Variables

Now that you know about the different primitive data types, we will go over how to assign these types to variables in Go.

In Go, we can define a variable with the keyword var followed by the name of the variable and the data type desired.

In the following example we will declare a variable called pi of type float64.

The keyword var is the first thing declared:

var pi float64

Followed by the name of our variable, pi:

var pi float64

And finally the data type float64:

var pi float64

We can optionally specify an initial value as well, such as 3.14:

var pi float64 = 3.14

Go is a statically typed language. Statically typed means that each statement in the program is checked at compile time. It also means that the data type is bound to the variable, whereas in dynamically linked languages, the data type is bound to the value.

For example, in Go, the type is declared when declaring a variable:

var pi float64 = 3.14
var week int = 7

Each of these variables could be a different data type if you declared them differently.

This is different from a language like PHP, where the data type is associated to the value:

$s = “sammy”;         // $s is automatically a string
$s = 123; // $s is automatically an integer

In the preceding code block, the first $s is a string because it is assigned the value “sammy”, and the second is an integer because it has the value 123.

Next, let’s look at more complex data types like arrays.


An array is an ordered sequence of elements. The capacity of an array is defined at creation time. Once an array has allocated its size, the size can no longer be changed. Because the size of an array is static, it means that it only allocates memory once. This makes arrays somewhat rigid to work with, but increases performance of your program. Because of this, arrays are typically used when optimizing programs. Slices, covered next, are more flexible, and constitute what you would think of as arrays in other languages.

Arrays are defined by declaring the size of the array, then the data type with the values defined between curly brackets { }.

An array of strings looks like this:

[3]string{“blue coral”, “staghorn coral”, “pillar coral”}

We can store an array in a variable and print it out:

coral := [3]string{“blue coral”, “staghorn coral”, “pillar coral”}
[blue coral staghorn coral pillar coral]

As mentioned before, slices are similar to arrays, but are much more flexible. Let’s take a look at this mutable data type.


slice is an ordered sequence of elements that can change in length. Slices can increase their size dynamically. When you add new items to a slice, if the slice does not have enough memory to store the new items, it will request more memory from the system as needed. Because a slice can be expanded to add more elements when needed, they are more commonly used than arrays.

Slices are defined by declaring the data type preceded by an opening and closing square bracket [] and having values between curly brackets { }.

A slice of integers looks like this:

[]int{-3, -2, -1, 0, 1, 2, 3}

A slice of floats looks like this:

[]float64{3.14, 9.23, 111.11, 312.12, 1.05}

A slice of strings looks like this:

[]string{“shark”, “cuttlefish”, “squid”, “mantis shrimp”}

Let’s define our slice of strings as seaCreatures:

seaCreatures := []string{“shark”, “cuttlefish”, “squid”, “mantis shrimp”}

We can print them out by calling the variable:


The output will look exactly like the list that we created:

[shark cuttlefish squid mantis shrimp]

We can use the append keyword to add an item to our slice. The following command will add the string value of seahorse to the slice:

seaCreatures = append(seaCreatures, “seahorse”)

You can verify it was added by printing it out:

[shark cuttlefish squid mantis shrimp seahorse]

As you can see, if you need to manage an unknown size of elements, a slice will be much more versatile than an array.


The map is Go’s built-in hash or dictionary type. Maps use keys and values as a pair to store data. This is useful in programming to quickly look up values by an index, or in this case, a key. For instance, you may want to keep a map of users, indexed by their user ID. The key would be the user ID, and the user object would be the value. A map is constructed by using the keyword map followed by the key data type in square brackets [ ], followed by the value data type and the key value pairs in curly braces.


Typically used to hold data that are related, such as the information contained in an ID, a map looks like this:

map[string]string{“name”: “Sammy”, “animal”: “shark”, “color”: “blue”, “location”: “ocean”}

You will notice that in addition to the curly braces, there are also colons throughout the map. The words to the left of the colons are the keys. Keys can be any comparable type in Go. Comparable types are primitive types like stringsints, etc. A primitive type is defined by the language, and not built from combining any other types. While they can be user-defined types, it’s considered best practice to keep them simple to avoid programming errors. The keys in the dictionary above are: nameanimalcolor, and location.

The words to the right of the colons are the values. Values can be comprised of any data type. The values in the dictionary above are: Sammysharkblue, and ocean.

Let’s store the map inside a variable and print it out:

sammy := map[string]string{“name”: “Sammy”, “animal”: “shark”, “color”: “blue”, “location”: “ocean”}

map[animal:shark color:blue location:ocean name:Sammy]

If we want to isolate Sammy’s color, we can do so by calling sammy[“color”]. Let’s print that out:


As maps offer key-value pairs for storing data, they can be important elements in your Go program.


At this point, you should have a better understanding of some of the major data types that are available for you to use in Go. Each of these data types will become important as you develop programming projects in the Go language.

Once you have a solid grasp of data types available to you in Go, you can learn How To Convert Data Types in order to change your data types according to the situation.

Originally published on

#go #database #web-development

What is GEEK

Buddha Community

Data Types in Go
 iOS App Dev

iOS App Dev


Your Data Architecture: Simple Best Practices for Your Data Strategy

If you accumulate data on which you base your decision-making as an organization, you should probably think about your data architecture and possible best practices.

If you accumulate data on which you base your decision-making as an organization, you most probably need to think about your data architecture and consider possible best practices. Gaining a competitive edge, remaining customer-centric to the greatest extent possible, and streamlining processes to get on-the-button outcomes can all be traced back to an organization’s capacity to build a future-ready data architecture.

In what follows, we offer a short overview of the overarching capabilities of data architecture. These include user-centricity, elasticity, robustness, and the capacity to ensure the seamless flow of data at all times. Added to these are automation enablement, plus security and data governance considerations. These points from our checklist for what we perceive to be an anticipatory analytics ecosystem.

#big data #data science #big data analytics #data analysis #data architecture #data transformation #data platform #data strategy #cloud data platform #data acquisition

Gerhard  Brink

Gerhard Brink


Getting Started With Data Lakes

Frameworks for Efficient Enterprise Analytics

The opportunities big data offers also come with very real challenges that many organizations are facing today. Often, it’s finding the most cost-effective, scalable way to store and process boundless volumes of data in multiple formats that come from a growing number of sources. Then organizations need the analytical capabilities and flexibility to turn this data into insights that can meet their specific business objectives.

This Refcard dives into how a data lake helps tackle these challenges at both ends — from its enhanced architecture that’s designed for efficient data ingestion, storage, and management to its advanced analytics functionality and performance flexibility. You’ll also explore key benefits and common use cases.


As technology continues to evolve with new data sources, such as IoT sensors and social media churning out large volumes of data, there has never been a better time to discuss the possibilities and challenges of managing such data for varying analytical insights. In this Refcard, we dig deep into how data lakes solve the problem of storing and processing enormous amounts of data. While doing so, we also explore the benefits of data lakes, their use cases, and how they differ from data warehouses (DWHs).

This is a preview of the Getting Started With Data Lakes Refcard. To read the entire Refcard, please download the PDF from the link above.

#big data #data analytics #data analysis #business analytics #data warehouse #data storage #data lake #data lake architecture #data lake governance #data lake management

Arvel  Parker

Arvel Parker


Basic Data Types in Python | Python Web Development For Beginners

At the end of 2019, Python is one of the fastest-growing programming languages. More than 10% of developers have opted for Python development.

In the programming world, Data types play an important role. Each Variable is stored in different data types and responsible for various functions. Python had two different objects, and They are mutable and immutable objects.

Table of Contents  hide

I Mutable objects

II Immutable objects

III Built-in data types in Python

Mutable objects

The Size and declared value and its sequence of the object can able to be modified called mutable objects.

Mutable Data Types are list, dict, set, byte array

Immutable objects

The Size and declared value and its sequence of the object can able to be modified.

Immutable data types are int, float, complex, String, tuples, bytes, and frozen sets.

id() and type() is used to know the Identity and data type of the object







Built-in data types in Python

a**=str(“Hello python world”)****#str**














Numbers (int,Float,Complex)

Numbers are stored in numeric Types. when a number is assigned to a variable, Python creates Number objects.

#signed interger




Python supports 3 types of numeric data.

int (signed integers like 20, 2, 225, etc.)

float (float is used to store floating-point numbers like 9.8, 3.1444, 89.52, etc.)

complex (complex numbers like 8.94j, 4.0 + 7.3j, etc.)

A complex number contains an ordered pair, i.e., a + ib where a and b denote the real and imaginary parts respectively).


The string can be represented as the sequence of characters in the quotation marks. In python, to define strings we can use single, double, or triple quotes.

# String Handling

‘Hello Python’

#single (') Quoted String

“Hello Python”

# Double (") Quoted String

“”“Hello Python”“”

‘’‘Hello Python’‘’

# triple (‘’') (“”") Quoted String

In python, string handling is a straightforward task, and python provides various built-in functions and operators for representing strings.

The operator “+” is used to concatenate strings and “*” is used to repeat the string.


output**:****‘Hello python’**

"python "*****2

'Output : Python python ’

#python web development #data types in python #list of all python data types #python data types #python datatypes #python types #python variable type

Cyrus  Kreiger

Cyrus Kreiger


How Has COVID-19 Impacted Data Science?

The COVID-19 pandemic disrupted supply chains and brought economies around the world to a standstill. In turn, businesses need access to accurate, timely data more than ever before. As a result, the demand for data analytics is skyrocketing as businesses try to navigate an uncertain future. However, the sudden surge in demand comes with its own set of challenges.

Here is how the COVID-19 pandemic is affecting the data industry and how enterprises can prepare for the data challenges to come in 2021 and beyond.

#big data #data #data analysis #data security #data integration #etl #data warehouse #data breach #elt

Macey  Kling

Macey Kling


Applications Of Data Science On 3D Imagery Data

CVDC 2020, the Computer Vision conference of the year, is scheduled for 13th and 14th of August to bring together the leading experts on Computer Vision from around the world. Organised by the Association of Data Scientists (ADaSCi), the premier global professional body of data science and machine learning professionals, it is a first-of-its-kind virtual conference on Computer Vision.

The second day of the conference started with quite an informative talk on the current pandemic situation. Speaking of talks, the second session “Application of Data Science Algorithms on 3D Imagery Data” was presented by Ramana M, who is the Principal Data Scientist in Analytics at Cyient Ltd.

Ramana talked about one of the most important assets of organisations, data and how the digital world is moving from using 2D data to 3D data for highly accurate information along with realistic user experiences.

The agenda of the talk included an introduction to 3D data, its applications and case studies, 3D data alignment, 3D data for object detection and two general case studies, which are-

  • Industrial metrology for quality assurance.
  • 3d object detection and its volumetric analysis.

This talk discussed the recent advances in 3D data processing, feature extraction methods, object type detection, object segmentation, and object measurements in different body cross-sections. It also covered the 3D imagery concepts, the various algorithms for faster data processing on the GPU environment, and the application of deep learning techniques for object detection and segmentation.

#developers corner #3d data #3d data alignment #applications of data science on 3d imagery data #computer vision #cvdc 2020 #deep learning techniques for 3d data #mesh data #point cloud data #uav data