Skip to main content


Condition Construct in GOLang

Condition Construct in GOLang Conditional programming is a very important construct available in all the programming languages. Go provides 2 conditional programming constructs If elseSwitch If Else This is a very basic construct and is similar to most of the other languages. If else can be written in the following way:
package main import "fmt" func main() { i := 10 if i > 10 { fmt.Println("Greater than 10") } else { fmt.Println("Less than 10") } }

We can also create an IF Else ladder in Golang
package main import "fmt" func main() { i := 7 if i > 10 { fmt.Println("Greater than 10") } else if i > 5 { fmt.Println("Greater than 5") } else { fmt.Println("Less than 5") } }
Switch Statement
Another alternative to IF Else is a Switch statement which is quite useful in Golang. Following is a very basic example of a switch statement
package main import "fmt" func main() { j …
Recent posts

Loops in GoLang

Loops Loops are one of the iterative constructs used in all programming languages to perform some task iteratively or to recurse over a data structure like a map or an array.
Many languages provide a set of FOR, WHILE and DO WHILE  loop but GoLang provides a different approach towards these three loops.
The only looping constructs available in Go is FOR.  Let's see how we can achieve different looping scenarios using GO.
Classic For loop Following is an example of how we can write the classic for loop with initialization, condition and increment step.
package main import "fmt" func main() { var i int //for initialization;condition; increment/decrement for i = 0; i < 10; i++ { fmt.Println("Inside the loop") } }

For with just condition (While loop) A while loop kind construct can be achieved using the for loop with just a condition and performing the initialization step before the loop and increment/decrement step inside the loop
package main import …

Advanced Data Types in Go

Introduction In my previous blog, I discussed the basic data types in Go. In this blog, we will be going a step ahead and learning about advanced data types in GO.
We will be talking about

ArraysSlicesMapsStructs Arrays Arrays as in other traditional languages are a collection of variables of homogeneous types i.e means instead of creating 10 variables to store same type of data let's say marks we create an array that can store 10 elements. Some of the key points about arrays in Go are: Arrays in Go are fixed sizeArray index starts from 0Same type of data can be stored in an arrayData Type has to be given while the array declaration The syntax for array declaration:
//Array declaration var arr [3]int //Indexing the array arr[0]=1 arr[1]=2 arr[2]=3
We can also use shorthand notation for the Arrays
//Array declaration and initialization arr1 := [3]int{1, 2, 3}

Slices Slices, on the other hand, is a data structure more flexible than arrays. They are similar to arrays in the sense that t…

Data Types in Go

GOLang Data Types Data types are one of the key things one has to know about while learning a language. They constitute the base of any programming language. I will be covering major data types that any programmer would be using throughout the day while working with GO. Without wasting enough time lets start with GO data types.
Basic Typesintfloat32float64boolstringsderived types Int Ints are used to store 32 or 64 bits integer values defined in GO as follows:
var i int = 122
The latter syntax is used when we want GO Compiler to pick the data type by inferring the value stored in the variable. Floats Floats are used to store decimal values in Go. Floats can be of two types float32float64 These two types correspond to the amount of space 32 bytes and 64 bytes respectively to store the numeric values. floats can be created in Go using the following syntax:
var f float32 = 1.1 var f64 float64 = 1.1
Bool Bool data type is used to store the boolean i.e true/false values in GO. The fol…

Writing first Go program

Introduction Nowadays there is a new buzz word in the IT world i.e Golang.
The need for a highly efficient yet simple programming language has lead to the creation of this new language name Go.

As per official documentation, Go is
The Go programming language is an open source project to make programmers more productive.Go is expressive, concise, clean, and efficient. Its concurrency mechanisms make it easy to write programs that get the most out of multicore and networked machines, while its novel type system enables flexible and modular program construction. Go compiles quickly to machine code yet has the convenience of garbage collection and the power of run-time reflection. It's a fast, statically typed, compiled language that feels like a dynamically typed, interpreted language. Being an IT professional and in my struggle for constantly updating myself with new tools I started learning Go.
I will be sharing my progress by writing blogs on my learnings.

Let's discuss writi…

Looping in R

LOOPS in R Loops are part of iterative programming where the user wants to perform a sequence of instructions N number of times.
R provides 3 styles of loops:For LoopWhile LoopRepeat Loop For Loop For loops are used when we want to iterate over a sequence like vectors and or data frames.
Syntax: v<-c(10,21,11,31,88,78) for(i in v){       print(i) }
This will iterate over all the elements of vector v.

For iterating over individual elements using the index one can use sequence vector and use it as index.

Syntax: v<-c(10,21,11,31,88,78) for(i in 1:length(v)){       print(v[i]) }

While Loop While loops are used when the iterations depend on a condition and it is difficult to predict the number of iterations.

Repeat Repeat is a new construct available only in R to run an infinite loop. Repeat block will iterate until a break statement is encountered.
i<-2 repeat{      print(i)      if(i>10){             …

Python Interview Questions

Hi Readers,

Writing the post after a long time, was looking out for job opportunities.

Facing around 10-15 interviews, I have experienced some of the common interview questions asked from a Python Developer and thought of creating a list of these questions.

Will create a  separate post for answers as well. Here is the list of interview questions for python interviews:

Which version of python have you worked with?What are MAGIC methods?What are DECORATORS?Write a decorator to add a '$' sign to a number.What are the different data types in python?What are mutable and immutable data types?Difference between list and tuples?Which one is faster to access list or a tuple and why?What is list comprehension?What is the use of negative indexing in the list?Why do we need list comprehension? How is it different from creating a list using a loopWhat are SETS in python? How are they different from LISTS?How SETS are internally stored in python?Which data types can be used as a key in a di…