Now that you know how to use Jupyter notebooks and have learnt how to write the basic “hello world!” program in Python, it’s time to understand how to declare a variable in Python. We will also learn about the different data types available in Python.
The following video will offer you an introduction to the basic syntax of declaring a variable in Python.
You have learnt that variables are nothing but a memory location to store values assigned to them. Some of the properties of these variables are:
There is no need to declare the data type of the variable as done in other programming languages, such as C, C++ and JAVA
int c = 5 string name = 'Rahul'
The variable name (or identifier) cannot start with a number, i.e., declaring something like 2name = 7 throws an error.
Python is case sensitive or in other words, these variables are case sensitive. This means that declaring name= 2 & Name = 4 would create two different variables.
In the previous video, you understood how to declare a variable in python. In this video, you will learn about common data types that are available in Python language and also learn how to find a type of a particular variable.
In the previous video, you learned about the various data types supported in Python. Now, let us move on and see how you can change a one data type to another in Python called as typecasting from the video given below.
In order to change the data type of a particular variable, you can simply call the following inbuilt methods in python.
In the above snapshot of code, you are assigning a value to a variable (x) and then using typecasting, converting it into different data types. So for example, when you convert x into an integer it converts the floating-point value into an integer value.