Hello guys. Welcome to Learnvern. In the last topic we saw what are the keywords available in Python.
We also saw the list & through the help function, we printed out the list, right?
Today we will see Datatypes in Python.
What are datatypes and how to use them? How do they work under Python?
So what is Datatype. Datatypes are used before Variables.
Such as Integer, Float, Characters, String…all of these are one type of datatype.
Datatype actually tells us what value is stored under your variable.
And it is an inbuilt class in one way which provides us with language.
Meaning if you are storing value in your variable in other languages without using datatype, then it is not possible.
But here in Python, you don’t need to define any datatype.
In whatever way you’ll pass the value in your variable, it will automatically assume its datatype.
For example, you took a value of A & stored 10 in it.
What is 10? It is a numeric value.
Python automatically recognises numeric values and will say that your variable is an integer type variable. Okay?
So how many builtin data types are there?
There are 5 types of data types.
Numeric, Sequence type, Boolean, Set & Dictionary.
I’ve drawn a diagram here & have explained that under numeric there is Integer, Float, Complex number.
In Boolean there is True & False.
Set means a set of values..
Dictionary meaning key & value.
Sequence means List, Tuple & String. All of these are builtin datatypes.
Now if I want to explain to you practically, we’ll have to go to Jupyter.
So I’ve opened up Jupyter here.
Suppose I want to show numerics here. Numeric.
In Numeric, first of all I’ll show you Integer.
Int Datatype. How will we do it?
I took a variable here A and gave its value 10.
Now if you want to know a particular variable’s type.
Like that particular variable is of what data type?
I have shown you the Type function under Basic Syntax.
I will further use it in Variable as well which I’ll show you in the next video.
So Print. Type function. And use A.
The outcome shows Integer. So you can check the type of any variable.
Suppose I’m taking a Float number. Float Datatype.
I took a variable named B and value 10.5.
Now I’ll check the type of value.
As soon as I passed B, it showed me Float.
Now it’s time for Complex Number.
Suppose an equation is made...like this…
Complex Datatype. Suppose I took 2 + 4J.
What was this? This was a complex number, right?
Now I’ll check its type. It resulted in a complex type.
You can check the datatypes this way in numeric,
Now if we talk about Boolean.
Boolean Datatype. How does that work? Let’s see.
Suppose I took a variable here D and wrote True here.
And I checked the type here of D.
What was the result? It came Bool which is the short form for Boolean.
Now I’ll write False here.
Suppose I took a variable E & wrote False. And checked its type.
It resulted again in Bool. That is Boolean.
Boolean has only 2 values that are True & False.
Boolean datatype will work only in these 2 values.
Now if I talk about Set.
How is Set datatype recognised?
Somehow like this…
Suppose I took a variable F...A, B, C...okay?
I’ve written 3 characters. Now I’ll check Print Type.
The type will be Set.
Meaning here the characters formed a set. Okay?
Set is recognised by a curly bracket and the values are stored normally only.
Now we will talk about Dictionary.
I’ll tell you later how we are going to go deeper in the Dictionary.
I’ll show you a simple example right now how the Dictionary datatype works.
Suppose I took a variable named X here.
Dictionary is also recognised by curly brackets.
There are 2 inputs.
1st is your key. And 2nd is your value. Okay?
Here one such dictionary will be made.
And if I check its type, the type will be Dict which is the short form of Dictionary.
There are sequence datatype just like this.
How does Sequence datatype work?
First we will check the list. How does list datatype work?
Suppose I took the L1 variable and entered 5 values under it.
And if I check the type of L1. Then I’ll get the list.
In future videos, I’m going to explain to you in much detail how the list works & how to use it.
Moving forward to String. How does String datatype work?
String is a normal collection of characters.
Suppose I took a string named Python Program.
I’ll check its type. We will use the Type function for that.
And we got String.
I’ll show String in detail as well in the future videos of this course which will make it easier for you to understand.
Next we will talk about Tuple.
How does Tuple datatype work? Let’s see that too.
Suppose I took a variable.
Tuple is recognised by a round bracket.
I wrote 1, 2, 3, 4, 5.
And I wrote Print. Type. And then Z.
You can see the result is Tuple.
So these datatypes are used in this manner under Python.
What did we see in today’s video?
We saw datatypes like Numeric datatype, Boolean datatype, Set datatype, Dictionary datatype, Sequence Datatype.
In the next video, we will work on variables.
A particular kind of data item as defined by the values it can take , the programming language used or to operations that can be performed on it.
A data type is implemented as a class in Python. The Charge class is defined in the charge.py file. The term class is used to define a class, followed by the class name, a colon, and a list of method definitions.
A data type limits the possible values for an expression, such as a variable or a function. This data type specifies the actions that can be performed on the data, as well as the data's meaning and storage options.
Lists, dictionaries, sets, and user-defined classes are examples of mutable data types in Python. Immutable data types, on the other hand, include int, float, decimal, bool, text, tuple, and range.
Arthik Nashik Chaware
I am satisfied to python and html faculty
Great Platform for learning.
the course is very good teaching and practical assignment