|

Data Type Part 2 | Python Tutorial in Sinhala Learn Basic of Python Programming #4 Video

Watch the video before you read this.

Why we use data types? In a programming language, we use data type to identify what type of data we have substituted for a variable.

Let`s see a simple example for a variable,

X = 1

In this example, this x is the variable. This X has been replaced by a value that has been replaced by an integer. If you do not understand Integer, I have made a video about it. Watch that video as well. Link Here >>>

Here it is clear to you that we are using this data type to identify what has been substituted for a variable.

Let’s go see what we are talking about today.

Today we are talking about the Sequence type, there are four types,

  1. Strings
  2. List
  3. Tuple
  4. Sets

OK, so let’s open the Python shell.

First let’s talk about string .For an example,

y = "pro"
type(y)

What we just did here is substituting “PRO” for y. We have now replaced it with a string. Let us now see if it is a string. Before you type the code press enter to submit an answer to the shell, after that we have to type, type(y) then you need to press enter to run this. Let see the answer,

<class 'str'>

Right now this ‘str’ is shortened to string. Now you can see that the type of this is String.

Let`s move to next example for that type

z = "Pasiya"
z

You can confirm if the value has been substituted for this variable by typing z and press enter. Now you can see the answer like this,

"Pasiya"

Okay, Let`s see the answer, you can simply type, type(z) then press enter.

<class 'str'>

Right now you can see that the answer is the same answer as before.

Let’s talk about Sets

For an example like this

x = {1 , 2 , 3}
type (x)

answer

<class 'set'>

Right now you can take care of what sets are simply. Of course, when we type in a set, we have to type inside the brackets.

Now let’s talk about list

In lists we use square brackets for represent list, Now you can see in this example.

t = [100 , 200 ,300]
type (t)

answer

<class 'list'>

Now you can see the answer, answer is list.

I will think about you have a good understanding of the list.

Fourth sequence type is Tuple.

Now you can see the an example for Tuple,

s = (22.3 , 56 , 89)
type  (s)

answer

<class 'tuple'>

Now you understand the tuple.

Okay, we ‘ve already talked about the four parts under the Sequence type. OK then we will learn how to find the range.

Let`s talk about Range

We will learn what it is by example,

list (range (5) 

Here we are looking at a range of numbers up to five. Okay let`s see the answer,

(0, 1, 2, 3, 4)

Now you can see the answer, but why not number 5 in the answer because we need to know python is known about the numbers to start at 0, So the answer with 0 output us five digits.

Next example,

a = range (5)

answer

range(0 , 5)

Here, I take ” a ” as the variable. So the outputs are 0 and 5

Let’s see how to find the multiplier next

I am looking for multiply by two. Let’s see how to do it.

list(range(2,10,2))

Here I typed 2 first because 2 times starts with 2 and then I want to see 2 times up to 10 times so I typed 10 and then I want to see 2 times multiplied by type 2 and press enter.

Now you can see the answer like this,

(2, 4, 6, 8)

As before, we are not shown the 10 in the output.

Okay I will take another example like that,

list(range(4,20,4))

answer

(4, 8, 12, 16)

Now you can see the output here. What I did here was looking at the 4 times to twenty. So then I hope you understood the sequence data type clearly.

Let`s talk about Dictionary type

Dictionary type is used to assign a value for a key. Now I`m taking a good example for a better understanding of this part. this example is Marks obtained by a group of students for an ICT subject in a class.

ict = {'Pasiya':'90', 'Lakmal':'80', 'Sandali':'75'}

You can confirm whether these values have replaced this variable by typing in the variable you took and press enter. let`s see the answer.

({'Pasiya':'90', 'Lakmal':'80', 'Sandali':'75'})

Now you can see our values are assigned to variable.

Let’s see how to get keys replaced by a variable.

ict.keys() 

answer

dict_keys({'Pasiya', 'Lakmal', 'Sandali'})

these are the keys in this example. Now I want to get a replacement for these keys. I will type this together,

ict.values()

answer

dict_values({'90', '80', '75'})

Now you can see the values are in those keys. Okay If you need an answer for a one key. How to do it. Okay I will teach you let`s see the code.

ict.get('Pasiya')

answer

90

Now you can see the answer. That is correct answer. Okay now you know about all the things about Data Types.

So that`s all We talked about in this video I hope you will learn anything from this video.

Subscribe My Channel for watch More Educational Contents.

Thank You.

Similar Posts

Leave a Reply

Your email address will not be published.