In the last topic, we worked with Datatype in Python.
Today we will work with Variables.
With what? Variables.
First of all, we have to know about variables.
What are variables? Variables are names to store some values.
To… store some values.
You can store any type of values over here.
You can store any data type value here.
Such as integers, float, string, boolean, set, tuple...all of these can be stored under variables.
There are certain rules to apply variables. What are those?
Whenever you start writing variables, it should start with alphabets only.
When you apply or create variables, it should not have whitespaces.
Whitepsaces mean you can’t keep spaces between A, B & C.
Your variables name should not be the same as datatype.
Meaning you can’t enter a variable as int, you can’t enter a variable as a float, you can’t take as double, you can’t take as boolean.
You can’t take variables the same as these, okay?
And particular variables are significant.
Meaning, if you’ve defined your variable in capital A and you’ve used it in small A below, it won’t identify the small A.
Which further means that if you’ve entered the name of the variable in capital, to call it, you must write that particular variable in capital only.
Only then your variable will be called.
You can use a variable in multiple ways.
Suppose you have to do multiple assignments with variables, then you can use it in multiple assignments.
I am going to show all of these things practically..how you can assign multiple variables.
Now suppose I want to concat certain variables.
Concat meaning if you’ve made 2 variables & you want to combine them.
You can use the + sign to concat both the variables.
Now how to use the variables, how to print them, how to use it with the user...we are going to see all of it practically.
First of all, I’ll open Jupyter. The Jupyter notebook has opened up.
Let’s see how to play with variables further ahead.
First of all...how to create a variable?
Creating a variable. Creating a variable.
I’ll assign an integer variable. Integer value to the variable.
Let’s see how to check it. Let’s see how to use it.
I took a variable A here & assigned 10 to it.
And I’ll run it. But for that, I’ll have to write Print.
Write A and 10 will be printed.
This is one type of Integer variable.
Which variable? Integer variable.
Now if you want to check that your variable is integer or not..
In the last video I explained the type function to you. Which function? Type function.
Let’s check that as well. Type. And use A.
What is the type of our variable? Integer type. Right?
You can assign the Float value in the same way.
Let’s see the Float value to the variable.
I’ll take a variable to be B.
I’ll assign its value 10.4 .
The point value is the floating value.
Now I'll print the B. It printed 10.4 as you can see.
If we check the type…we have a Type function to check type.
We’ll type B. You can see that it provides us with float as well.
We will use string in the same way.
Let’s see with the string.
I wrote in the comments String value to the variable.
I’ll take a third variable C. I’ll assign Python here.
Python is a string. I’ll print it. Print C.
You can see that Python got printed here.
Now if I want to check the type of C as well, I’ll use the type function.
And pass C under it. The string will be assigned as well.
When we will learn about Data structure such as list, tuple and dictionary ahead,
I’ll tell you about this at that time as well…
That you can store a list in a particular variable as well.
List store in variable. Let’s see how we can do it.
I’m taking a variable named L1 here.
Square bracket to store the list. I made a list of 1, 2, 3, 4, 5, 6.
Now I’ll print L1. And the list is printed.
Now I want to check if my variable is made of that particular list or not?
We shall check that with the type function through L1.
It did show us that it is one type of list. Alright?
That our list is stored under this variable.
We will store Tuple in the same way..okay?
Tuple store in variable.
I took a variable named T1.
Gave an input of 1, 2, 3, 4, 5. 5 values under Tuple.
Further ahead I'll print T1. And you can see it got printed below.
Now I want to check its type.
We will check it through the Type function with T1.
And run it. Tuple got printed down below as well.
Inshort, you can store anything in a variable as well as work along with the variable as well.
But one most important thing is that you should know the rules of the variables and work according to the rules only.
So in this way you can store any data in variables
Next we are going to work with Type conversion.
For instance, I’ll write here Type Conversion.
Now what does Type conversion mean?
Suppose you want to convert the Type of the variable.
Meaning from one data type…
Let me write here converting from 1 datatype to another datatype is called Type conversion.
Or you can call it Type casting as well.
What is its other name? Type casting.
I’ll pass it as a multiline comment.
So this is how you can use type conversion.
Now let’s see how to use Type conversion.
I want to convert the type of a particular variable...
Suppose I have a variable called A under which I want integer value only, that too from the user.
So what will I do? I’ll take an input and write a message saying Enter the value of A.
Now I’ll only get the value of A printed out.
Right now I have not applied type conversion yet.
I’ll just print Type and put the variable A.
We will run it now.
Suppose I write 10, 10 is an integer but you see what its datatype is?
It is showing the datatype String. We all know 10 is not a string.
So for that, we have to convert its type so that we only and only get integer in its type value.
So I’ll apply for a type conversion. How will I do it?
You just have to type Int. here & put the whole input function under Int’s parameter.
Now I’ll enter 10 & it will give integer as the answer...okay?
But you can’t enter a string here.
As soon as you input a string here, it’ll prompt an error.
That what you’ve input is not a type conversion.
Why isn't it? Because string data types cannot be converted into anything.
While you can use any datatype under string. Got it?
So it won’t be converted.
Now if i write 10, it will allow me.
So this is how you can use type conversion with variables.
I hope you understood the concept so far.
So what did we see today in variables?
We saw how to create variables, how you can assign integer value, float value, string, list, tuple...and we also saw type conversion in Python.
So this is how you can use variables in Python.
Our next video's topic will be about Operators.
A Python variable is a memory region set aside for storing values. A variable in a Python programme, in other words, provides data to the computer for processing. In Python, each value has a datatype. Numbers, Lists, Tuples, Strings, Dictionary, and other data types exist in Python.
int (signed integers)
long (long integers, they can also be represented in octal and hexadecimal)
float (floating point real values)
complex (complex numbers)
There are two ways in which you can assign values to variables in Python:
Assignment statements - This is the most common way of assigning values to variables in Python - Syntax:- variable_name = value (e.g.: my_age = 24)
Assignment operators - You can also assign values to variables by using assignment operators instead of assignment statements (e.g.: my_age += 1)
Variables store data, or information. Data can be treated as variables if it is given a name, set of values, and assigned to an appropriate data type. For example, the average temperature in Fahrenheit can be stored in a variable called temperature_fahrenheit.
Best of all beginners
Good learning app
SN gateway creation
when write code show this error - OperationalError: (1115, "Unknown character set: 'utf8mb4'")
how to solve it
if Else ladder,
input data from user this not taking all numbers values like 45.5, 75.05
kindly give the idea ...
This website is amazing, and helping us to beginners to improve yourself skills. I appreciate this website, and website owner work is excellent. Thanks
Respected LearnVern Team Course content not working in the Python course ( video not playing)
other course and overall platform is very good Thank you.
Shubham Ramesh Sonwane
It was a very fantastic course. But I have to suggest something To your team, when I complete the assignment how can I check if my My solution is correct or not. thank you