Julia Basics of programming, Data types, Numerical operations
By: Akash Deep
Tags: Julialang, Julia

Julia

In this article we will try to understand the basics of Julia programming mainly about the data types, string operation and many more, as we all know that these are the basic building blocks of any programming language. By combining theses basic building blocks we can write the use case and can design any products. In my last article we already discussed what is Julia and how to install julia and use the same in Jupyter notebook. I highly recommend to go through that article and try to understand what is julia and what is the scope of it. Link for the previous article is listed below

As Ihave mentioned earlier, If you knows python, it will be very helpful and easy to learn Julia because one can easily co-relate the concepts of programming language like class, object, inheritance, garbage collector and many more. If you don’t have python background don’t worry, i will try to keep the concepts in very simple and self explainable. Still if you want to clarify anything that you are not understanding, feel free to comment below, i will be very happy to address. In last tutorial I already discussed how to install Julia in Jupyter IDE, this is important because we are going to practice Julia over Jupyter notebook.

Airthmetic Operation

In julia if you want to perform any airthmetic operation, it is very simple, same as python just write the operations what we want to perform with operand. One thing we need to understand is “2//2" will be treated as string in julia. About BODMAS rule, it is same as any other programming language like python, java etc i.e, first bracket then order then division after multiplication after addition and at last substraction operation will be performed if you have the set of airtmetic operation you need to perform, it will follow BODMAS rule. In Julia if we want to print the exponential statement we will be specifying as “10^ 2” but in python we know if we want to perform the same operation we can use “10**2”. Screenshot of some of the airthmetic operations are provided below

Airthmetic operation in Julia

Checking Data types

Checking data types is also one of the main task which is very useful if you are writing any complex code or if you want to use the response output further in any kind of integration of the products. As we all know in python data type checking we use to do with the type() keyword. In Julia we will check with the keyword called typeof() .

typeof()

Boolean operation

In Julia, we have keyword called “true” and “false” for the boolean operation. In python we have “True” and “False” keyword. Only the difference, In Julia it starts with small letter.

Boolean

String definition

In python we know that we can define string in single as well as double quote, i mean if we want to define akash as a string in python we can do it in “akash” or ‘akash’, both way are fine. But In julia, if we are defining any string we need to put the string only in double quotes like “akash” if we put it in single quotes we will encounter with error. In below example we are seeing that if we try to define the string in single quotes error has been encountered in julia. If we want to initialize multi-line string in Julia we need to specify the muli-line string under “ “ “ ” ” ” 3 open and close double quotes same as in python.

String definition

Variable initialization

In Julia, defining or initializing variable is very simple as same as python. We don’t need to specify the Data types of variable while assignment that we generally used to do in c++ or java. In Julia, compiler will automatically understand the type of variable, that we had assigned, we don’t need to explicitly specify the type of variable.

Variable assignment

Print function

In Julia we have function called print() and println() for printing any statement. We all know in python we have only one print function i.e, print(). println() in Julia specifies the printing of the statement in the new line. In python we don’t have any function called println().

Print statement

String Formatting

String formatting is one of the useful feature of any programming language. In Julia string formatting is very simple just we need to specify the parameter that needs to be formatted inside the string function. We have 2 string variable str1 and str2 and we want to concatenate the two string, we will specify both string str1 and str2 as a parameter in string function and it will result in the concatenation of the two string. In the same way we can concatenate multiple strings. Regarding string formatting, it is very simple in case of Julia. In python we generally need to use the format() function to perform the string formatting but in Julia we just need to specify the string needs to be formatted with dollar symbol inside the print statement and also we can perform any airthmetic operation by just specifying it in small bracket. We will see the example below.

String formatting and concatenation

Julia Comments

Commenting is one of the most useful practice while dealing with any programming language, because if you are writing any frameworks or developing any application in the organization we need to follow the practice of commenting the code as it will be helpful for other people who will be seeing your code in future and sometimes it will be helpful to you as well because we might forget the behaviour of your code in future and also it is very helpful when you will be updating your code and performing any debugging operations. In python we already know if we want to specify single line comment we just make use of “#” symbol and just write the comment. In Julia, the same way we will follow to specify the single line comment. Any statement which we want to comment we will just specify under “#” symbol. If we want to perform multi line comment we can make use of “#=” at starting of the comment and at the end of the comment we will just use the above statement in the reverse way like this “=#”. See the example below

Julia Comments

In this article we had discussed the very basic Julia operations and tried to understand the concepts and syntax. If you have any doubts or any confusion please comment below in the comment box I will happy to help you out and if you want to know more about data science and the DL and ML concepts i suggest check my previous article, I am sure it will be helpful. In the upcoming article under Julia tutorial we will be discussing the more advance concept and syntax that will be very helpful for the further building blocks when we will see Machine learning using Julia.

Stay Tuned