Basic data types in Python language
In today’s post, I am going to cover the basics concepts of the python programming language.
Although most of the data science tutorials on the internet start of with libraries like numpy, sci-kit-learn and pandas it would be better if we first try to cover the absolute basic data types and syntax and how to play around with them before we deep dive into specific libraries because sometimes it’s good to watch individual Avengers and Guardians of Galaxy movies before trying to soak in the awesomeness of Avengers as a whole.
Let’s start off with basic data types:-
Numbers:- In python, numbers are represented either by using integers or float.
Strings:- Any collection of characters viz words or sentences are represented using strings in almost all of the programming languages.
The list of methods that can be used to manipulate lists are as follows:-
The first thing to keep in mind is that indexes start from 0 in python therefore when we print “user” in the second line we actually get “o” which is the second character in the string. We have used “:” operator in the third line to specify the range of characters which we want to extract from a string. So when we specify the range from 1 to 3 above, we actually starting from the second character i.e. index 1 till index 3 i.e. 4th character.
Some of the methods of python lists are:-
Keep in mind that if we use a negative value as an index then python will start counting items from the end of the list. For example, using “-1” as the index will print the last value from the given list.
In order to get specific items from the above list we can make use of “:” operator similar what we did in the case of a list.
Tuples are other data types similar to lists. They differ from lists in the following ways:
- They start and end with a parenthesis() instead of square brackets.
- They are immutable i.e. they cannot be changed once declared. So think of tuples as read-only lists.
Let cover some basic tuples operations:-
Let’s cover basic arithmetic operations in the snippet below:
There are 3 main logical operators in python:-
Well, that finishes of today’s basic tutorial. In the next one, we will try to cover conditional loops and how to define functions in python language.