Posts

Showing posts with the label programming

Enums in Go - Iota

Image
 Yes, you read it right. Like many other languages Go support the concept of enums through the IOTA function. IOTA According to Go documentation  Within a  constant declaration , the predeclared identifier  iota  represents successive untyped integer  constants . Its value is the index of the respective  ConstSpec  in that constant declaration, starting at zero. It can be used to construct a set of related constants.   Don't worry if you didn't get it. Basically, Iota is a keyword in Go that helps you to give random values to your constant. Let's say you want to define 7 constant Monday, Tuesday, Wednesday .... Sunday. Easy way to do this is const ( Monday = 1 Tuesday = 2 Wednesday = 3 Thursday = 4 Friday = 5 Saturday = 6 ) In this situation, values 1,2,3,4,5,6 don't make much sense. The only thing these values should follow is that they have to be unique i.e Monday should ...

Dictionaries in Python in 5 mins

Image
What is a Dictionary or Dict? A dictionary is a data type used to store key-value pairs as we have in our English dictionary. It is useful when we want to save the data related to an entity at the same place. It is like saving an excel row in python in a column_header:column_value format E.g If we want to store the details(name, class, marks, address) of a student we can create different variables for this, or we can create only one variable of type dict and save the values in it. Syntax: s1={ ‘Name’:’Tarun’, ‘Class’: 12, ‘Address’:’house number 11 xyz street ‘,           ‘marks’:[90,89,67,84]       } As in the above code, we can see that a dictionary can save multiple data types. Variable “Name” is of type string, “Class” is of type int, “Address” is of type string, “Marks” is of type list.  A dict can also store a dictionary in it and is called Nested Dictionary. Syntax : <variable name>=dict({key:value,key:value}) <vari...

Variable and Data Types in Python

Image
Variables in Python A variable is a named storage location where you can save some value when you execute your code. It takes some space in your RAM and its value persists till the time your code is executing. E.g # Without variables  # Add two numbers print(10+20) #With variables a=20 b=20 print(a+b) The benefit of saving your values to a variable is that the values and calculation (addition in our case addition) can be reused in some further parts of the code. Comments A comment is a line in your code that you don’t want to run but write them just for some reference in your code like explaining what your code is doing. E.g #this line do addition c=a+b In python, comments can be done using a ‘ # ’ symbol in the start of the line. It will inform the interpreter not to execute that line. Data Types in Python A data type in python refers to different formats of data that we can use in python. We are not always working with the same type of data. For example, to store the details of a...

Hello World Program in Python

Image
What is Python? Python is a very powerful programming language and can be used to write any piece of software. But you can also use it to do data science. Model your sales data, to text mining on your latest Twitter feeds, or build the next movie recommendation engine. It's all possible with Python. Python is open source, and there's a bunch of programmers across the world that have written amazing extensions to Python, to help you achieve great things. Python can be used in the cases where the legacy analytical tools fail. Before we start to learn the python program following is a list of some commands which can we will be mostly using while working with python: For Linux / Mac pwd: prints present working directory (folder) of the terminal cd: It is used to change the directory (folder) from the terminal cd... : used to go one directory back cd<directory name >: used to go to child directory from the parent directory ls: to print all the folders in the current folder mk...

Python 2 Vs Python 3

Image
There has been a huge debate on this topic, " Whether you should learn Python 2 or Python 3". If you are also in this dilemma this post is for you. The first thing you should understand is that if an upgrade is done in anything in the world it is mostly for improving that thing in terms of experience, speed, efficiency, etc. So, this upgrade of Python language is also done to improve the features and functionality of the language but than, Why is this debate all around about Python 2 and Python 3, why can't people just accept this new update rather than debating. To understand this you will have to think deeply and understand that Python has been there for nearly 29 years now(created in 1991), there are large number of legacy systems which are built on Python 2 and there are some feature of Python 3 which are not backward compatible with Python 2. For Example:  The scenario of a simple print statement. In Python 2 print was considered as a statement and in Python 3 it is ...

Why should you learn PYTHON in 2020

Image
What is Coding/Programming? For all those who are very new to coding/programming and are about to start their journey by reading this blog post.  We give instructions to our system using the keyboard or mouse informing the computer to perform some set of tasks like: Printing a doc Writing an email Playing music Dimming the monitor backlight and many more tasks The computer is a hardware device which needs some instructions to run and when we are performing some tasks on the computer, in the background there is some code which is running and telling the computer machine what it has to do. And this happens with the help of some programming language, which acts as an interface between the computer user and hardware. So, coding/programming is an act of writing these instructions using some programming language which when runs on a computer performs some tasks. Pheww...... Programming Languages There is a large variety of programming languages available in the market right now and every...

Error Handling in R

Image
What is an Exception? An unwanted situation that may arise while your code is getting exected is called an Exception e.g when your code attempts to divide a value by zero. Exception Handling Exception handling is the process of handling the errors that might occur in the code and avoid abrupt halt of the code. In simple English, our code should either end by performing the intended task or prints a useful message if it is not able to complete the task. We have this code which has non-numeric value in the list and we are trying to divide  5 with every element of vector v #a list with one non numeric value v<-list(1,2,4, '0' ,5) for (i in v) { print(5/i) } Here we can see that the code has not printed any result and has stopped abruptly. To avoid these situations we use exception handling constructs available in R Exception Handling Constructs in R try tryCatch Using try We need to enclose the objectionable statements ...

Data Types in Go

Image
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 Types int float32 float64 bool strings derived types Int Ints are used to store 32 or 64 bits integer values defined in GO as follows: var i int = 122 i:=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 float32 float64 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 Bo...

Writing first Go program

Image
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 lea...