Found 1082 Articles for Go Programming

Golang program to convert array into slice

Akhil Sharma
Updated on 13-Feb-2023 16:04:40

3K+ Views

A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas slice is a dynamic array which means its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover they are passed by reference instead by value. Method 1: Using [:] In this method, we will using [:] for slicing an array. After the conversion of array into slice, we will print the output on the console using print statement in Golang. Algorithm Step 1 − Create a package main and declare fmt(format ... Read More

Golang program to calculate difference between two slices

Akhil Sharma
Updated on 13-Feb-2023 16:03:23

3K+ Views

A slice can also be called as dynamic array as it's value is dynamic whereas normal array is static. This makes slice more efficient and faster. They are passed by reference instead by value. Here we are going to learn about how can we find the difference between two slices or two dynamic arrays. Syntax func make ([] type, size, capacity) The make function in go language is used to create an array/map it accepts the type of variable to be created, its size and capacity as arguments func append(slice, element_1, element_2…, element_N) []T The append function is ... Read More

Golang Program to Calculate the intersection of two Slices

Akhil Sharma
Updated on 13-Feb-2023 16:01:20

1K+ Views

In Golang, a slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas slice is a dynamic array which means its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover they are passed by reference instead by value. Syntax func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an array slice. It takes number of arguments. The first argument is the array to which we wish to add the values followed by the values to add. ... Read More

Golang program to calculate union of two slices

Akhil Sharma
Updated on 13-Feb-2023 15:59:54

1K+ Views

In golang, a slice is known as dynamic array where it's value is not fixed and can be changed. It is more efficient and faster compared to simple arrays. In this article, we are going to learn how to calculate a union of two different slices using examples. Syntax func make ([] type, size, capacity) The make function in go language is used to create an array/map it accepts the type of variable to be created, its size and capacity as arguments func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an ... Read More

Golang program to split a slice into two halves

Akhil Sharma
Updated on 13-Feb-2023 15:58:37

2K+ Views

A slice can also be called as a dynamic array as it's value is dynamic whereas normal array is static. This makes slice more efficient and faster. They are passed by reference instead by value. Let us learn how to split a slice into two halves using Golang program. Syntax func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an array slice. It takes number of arguments. The first argument is the array to which we wish to add the values followed by the values to add. The function then returns the final ... Read More

Golang program to merge two slices

Akhil Sharma
Updated on 13-Feb-2023 15:57:29

4K+ Views

In Golang, a slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas slice is a dynamic array which means its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover they are passed by reference instead by value. Syntax func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an array slice. It takes number of arguments. The first argument is the array to which we wish to add the values followed by the values to add. ... Read More

Which is better for future skills, Go or Python?

Vikram Chiluka
Updated on 01-Feb-2023 20:06:05

1K+ Views

In this article, we will learn Which is better for future skills, Go or Python. Both Python and Golang are advanced web languages. Which one should an experienced programmer or Web developer select? Let us see in brief. Scope in 2023: Golang vs. Python Put web development on hold for now, while we analyze the value of learning Golang. Python is an advanced and powerful language that can handle a variety of development tasks. It is an object-oriented, structured programming language that is interpreted. Python aids in the development of various software, business applications, ERP, eCommerce, and desktop GUIs. AI ... Read More

Golang program to show overriding of methods in classes

Akhil Sharma
Updated on 01-Feb-2023 19:17:40

3K+ Views

When a method is overridden in Go, a new method with the same name and receiver type as an existing method is created and used in place of the existing one. As a result, Golang may provide polymorphism, allowing different implementations of a same method to be used depending on the type of receiver. Let’ see the execution in examples. Method 1: Using shape struct Here, this shape struct will contain an area field and an area method which will return the value of area field. Rectangle and square both inherit the area () method. The output will be their ... Read More

Golang program to show overloading of methods in class

Akhil Sharma
Updated on 01-Feb-2023 19:16:13

2K+ Views

In this article, we will learn how to overload the method in class using different example. Go programming language does not have concept of a class so function overloading will be used to execute the program. As a result, code can be more flexible and readable. As an illustration, you could create a function that accepts an interface as a parameter and then call it with several types that implement the interface. Let’s see it execution. Method 1: using custom type MyInt Here, it contains two methods Print() and PrintWithNumber() where values can be sent in these functions of MyInt ... Read More

Golang program to check if a string is empty or null

Akhil Sharma
Updated on 01-Feb-2023 19:15:03

13K+ Views

String in Golang is a collection of characters. Since strings in Go are immutable, they cannot be modified after they have been produced. Concatenating or adding to an existing string, however, enables the creation of new strings. A built-in type in Go, the string type can be used in a variety of ways much like any other data type. Syntax strings.TrimSpace() To eliminate leading and trailing white space from a string, use the strings.TrimSpace() function. Algorithm Step 1 − Create a package main and declare fmt(format package) package. Step 2 − Create a main function. Step 3 − Using internal ... Read More

Advertisements