Free YouTube Transcribe

Video transcript

Variables and Data Types | Python Tutorial - Day #6

CodeWithHarry · 3,047 words · 14 min read

Want to search this transcript, jump the video from any line, or download it as TXT, SRT, or VTT?

Open in the transcript tool

Full transcript

0:00Damn guys! You're here on day 6 too on 100 Days Of Code series

0:04This is what I wanted

0:05Today I'll tell you "What are variables"

0:07Variables are like containers just like you have in your kitchen

0:11In which you store lentils, flour & rice etc

0:13In Python Programming Language 'Variables' are just like those containers

0:16This analogy fits completely on the explanation of variables

0:18Let's suppose I've a container in my hand

0:21And let's suppose this container contains lentils

0:23And let's suppose that I replace those lentils with rice

0:26So basically I just changed the content of this container

0:29On the other hand, let's suppose if I take another container

0:33And in this container if I put some water and then I put some milk

0:37So I can change it's content

0:39This is exactly what happens in Python as well.

0:41That you people make containers and stores data in them.

0:45And this data is stored in the memory.

0:47It is stored in it, what you call 'RAM'

0:50What is 'Data Type' ?

0:51Just like a container can contain 'Liquid' 'Solid' 'Lentils' or 'Sugar'

0:57Even maybe there is something that is not even edible

1:00We have a lot of items

1:02For eg. liquid dish wash, that liquid is not edible

1:05So there are 'types' of everything

1:07Just like that there are 'Types' in Python which we refer as 'Data Types'

1:11Let's quickly move to the computer screen and learn "What exactly 'Data Types' are"

1:16And how they operates.

1:17Let's get started

1:18[

1:18[S

1:18[ST

1:18[STA

1:18[STAR

1:19[START

1:19[STARTI

1:19[STARTIN

1:19[STARTING

1:19[STARTING

1:19[STARTING T

1:20[STARTING TH

1:20[STARTING THE

1:20[STARTING THEM

1:20[STARTING THEME

1:20[STARTING THEME]

1:27So exactly what are these 'Variables'. Let's check it out first.

1:30Variables are like containers, like I've told you already.

1:34But what type of container is this?

1:35This container is inside the memory

1:37Now, if you're confused about all this stuff.

1:39So move to the 'main.py' and have a look what am I doing here

1:45Then you'll get to know

1:46That how exactly you have to make 'Variables' in Python

1:50Why is it important to make 'Variables' in Python

1:53Look, if I write here "a = 1"

1:55I just need to do this. And then if I wrote "print(a)"

1:58I'm just basically commanding it to store 1 in my computer's memory or 'RAM'

2:04Store 1 in its actual memory

2:08And the place where it is stored

2:10Give that address to " a "

2:12Now this might sounds complex to you

2:15But whenever I use " a " after writing " a = 1"

2:19Which means whenever I want to refer its value

2:23I'll just print " a "

2:24Now you'll say I memorized " a = 1 " shouldn't I just directly print ( 1 )

2:27Why should I run this program?

2:29How about this? If I do this, so you made a program to save a number

2:34A number has been saved here and it is being printed

2:37So writing " a = 'whatever the number' " result in saving this number in " a "

2:41And by writing " print(a) " will result in " printing(a) "

2:43Can I write it like ' b = "Harry" ' ?

2:47The answer is...

2:48Yes I can

2:50But if I run this so, I'll only get this number printed

2:53And if I print(b)

2:56So you'll see that I'll get this "Harry" printed

2:59Which is great man!

3:00Because this is a different 'Data Type' and this one is a different 'Data Type'

3:03Now you'll say "Harry bhai when you wrote this number, you didn't use double-quotes(" ") "

3:09But when you wrote "Harry" why didn't you wrote it without double-quotes(" ")

3:12That is because it will throw an error.

3:14Now why will it throw an error?

3:15You'll ask "I can directly write 'Harry' "

3:18But.....

3:19We have to use double-quotes(" ") while representing an string 'Data Type'

3:24So that... It's possible that someone has written it like "Harry = 9"

3:29Now one can write "B = 'Harry' "

3:31Now how will Python know what you want to print "Harry" the 'String' or the '9'

3:35If I run this program so look, I'll get this '9' printed

3:38Look, 9 will be printed here

3:41It's possible that you literally want to print this "harry"

3:44But '9' will be printed

3:45That's why there are some rules in Python

3:47So let me remove it for now

3:48If I write ' b = "Harry" ' so directly the content of " b " will be printed

3:52As you all can see

3:54Now let me tell you what I've written for you

3:58So look. "What is 'Variable' " ?

3:59"Variable is like a container that holds data."

4:02"A container that holds data"

4:03Very similar to how our containers in kitchen holds sugar

4:07Just like containers used in your kitchen to hold salt, sugar etc

4:15Creating a variable is just like creating a placeholder in memory and assigning it some value.

4:18And here I've declared 4 types of 'Variables' 'a' 'b' 'c' & 'd'

4:23Now all these 4 'Variables' are of different kind

4:25Which means they are of different kind

4:27For eg. let's suppose you're a living being

4:31And there's a dog, he's also a living being

4:33And an ant is another living being

4:35But we all are different kind of living beings

4:38Same like that " a = 1 " is a different kind of 'Variable'

4:40" b = true " is a different kind of 'Variable'

4:42' c = "Harry" ' is of a different kind & " d = none " is a of different kind

4:46You're still watching this video on 1x

4:48Now if I've written " a = 1 "

4:51An integer has been stored in " a "

4:53When I wrote " b = true " so a Boolean has been stored in " b "

4:56' c = "Harry" ' result in storing a 'String'

4:58And " d = none " type

5:00.....

5:01When I wrote " d = none " so a 'None' type variable has been created here

5:05So these are 4 different kind of 'Data Types'

5:08What is 'Data Type' ?

5:09And why we need them?

5:10Look, I already have told you "Why we need 'Data Type' ? "

5:14That we need 'Data Type' so that we can store different type of values in memory

5:20OK! We know that

5:21'Data Type' specifies the type of value that a 'Variable' can store

5:26This is required in programming to perform operations

5:29For eg. Let's suppose if I write here...

5:32..." print(a + b)"

5:35So will it add "Harry" in it?

5:36Look it'll throw an error

5:38It is saying...

5:39...." You're trying to add an 'Integer' and a 'String' "

5:42" What are you trying to do? "

5:44Even if I decrease this number...

5:46"How can you add 'Harry' in '123' What do you want? What's your plan?"

5:50This is what Python is saying

5:54And we are telling Python that "We want to concatenate"

5:58So Python will say "How will I know that you don't want to concatenate or anything else, you're using the (+) sign"

6:06So that' why whenever we do (a+b) we keep this in mind that those 2 must be of same 'Data Type'

6:13So I'll do one thing...

6:15I'll create a variable with name (a1 = 9) and now if I add ( a & a1 )

6:19Then this operation will be performed successfully

6:22And look " 132 " will be printed here

6:24So this was very simple, you might already know this

6:27But we need 'Data Type' so that...

6:30...We can perform various operations without causing an error

6:34Without causing an error

6:35In python, we can print the type of any operator using type function:

6:39Suppose a variable has been created

6:40And I want to know its type

6:43So I can do that in this manner I can write "The type of a is... "

6:48And here by adding a comma(,) I can write " type(a) "

6:55So I've closed the bracket of ' type(a) '

6:58And now I've closed the bracket of this opening parenthesis

7:02Now if I run it, so look....

7:04" The type of a is <class 'Int'> "

7:06' a ' is an 'Integer'

7:08Let's see if we can do the same with 'b'

7:13I'll try to run it....

7:15And look, " The type of b is <class 'Str'> "

7:19And now if I do the same with the type(c)

7:25And look what's the type of 'c' is... There's nothing with name ( c )

7:28Let me try for 'a1'

7:30Or let me create 'c'

7:32What if I create all these 4 variables at once

7:37So there won't be any headache I now have all four variables (a, b, c & d)

7:41Now if I run it so the type of 'c' will be...

7:45It is saying " name 'a1' is not defined "

7:47I've written " print(a + a1)

7:49No problem, let me define 'a1' because I've to give this program to you

7:55So look I've written " a = 1 " So "1" "true" & "10" has been printed

7:59The type of a is <class 'int'> The type of b is <class 'bool'> & The type of c is <class 'str'>

8:03It has printed the type of all 3

8:05OK, Great! We got all the points till here

8:09Now let me tell you there are some built-in 'Data Types' in Python

8:12The first built-in 'Data Type' is 'Number'

8:16Which I already have told you

8:18'Int' 'Float' & 'Complex'

8:20Now if I change this 'a' to 1.1 from 1 Do you remember its type was 'Int'

8:26If I change 'a' to 1.1 so its type will be 'Float'

8:30And if I tweak it like....

8:32If I write it like "8+2i" so it'll become a 'Complex' number

8:38Actually to create a 'Complex' number I've to do something like this

8:42I'll write " 8,2 "

8:44And when I'll write this so a complex number will be created

8:47And look, a complex number has been created with name "8 + 2j "

8:53If you don't know about 'Complex' number is So that's totally fine

8:56I don't expect you to know 'Complex' numbers

8:58But I just want to tell that you can also create 'Complex' number in Python

9:02Basically these are the numbers with real part & imaginary part if you've studied 'Complex' numbers in +2, Good for you

9:08But if you haven't studied this in +1 or +2 BTW it's the topic of +1

9:12But different boards have different syllabuses

9:17So some students studies this in +1 and some in +2

9:19Anyways....

9:19It is showing its type as 'Complex' I just want to show you that..

9:23It has become a 'Complex' number

9:25So look I've written that the numbers can be of 'Integer' type or 'Floating Point Number'

9:29Or 'Complex' type

9:30And along with that if we talk about 'String'

9:32"Hello World!!!", "Python Programming" enclosed in double-quotes(" ")...

9:37...These are of 'String' type

9:39Now if I talk about 'Boolean' data, so they can either be True or False

9:43Now why we'd like to use them?

9:46Let's suppose you write a function

9:48And you want to return the driving test as 'Pass' or 'Fail'

9:52If you don't know what functions are.. So let me tell you

9:55Let's suppose if you want to tell me that if I'm able to drive or not

9:59So you can just give a minor information In type of 'Yes' or 'No'

10:04So this is the work 'Boolean' perform

10:07You don't directly have to say "Yes! You can drive"

10:10You don't need to give all these information

10:13You can either say 'Yes' or 'No'

10:14'Yes' means 'True' or else 'False'

10:17Just like 'String' contains a lot of values like 'HARRY' and many other characters

10:22But if you want to tell me, if I'm able to drive or not

10:25So you can say 'Yes' or 'No'

10:28And you should be good

10:30So this is Boolean 'Data Type'

10:32Why we use that?

10:34And when we should use that? We'll talk this later

10:37And then comes the 'Sequence' Data

10:39I'll now talk about 'List & Tuples'

10:41And there's no need for us to dive deep in 'List & Tuples'

10:44I just want to tell you that there's something named 'List & Tuples'

10:47What is 'List' ? List is an ordered collection of 'Data Types'

10:50And we'll study this later so I won't tell much about that right now

10:53And if you want to know about 'List'

10:56Hold your horses man!

10:58I'll tell you about 'List'

11:01Now what is 'List' ? List is basically a collection of different data elements

11:06Elements which can be of different kinds For eg. This is a 'Integer' and this is a 'Float'

11:09Added a list in a list and another list

11:12So basically 'List' is a List of items which can be of different 'Data Types'

11:16For now I'll only explain this, not much

11:19And we can make changes in 'List'

11:21What is 'Tuple'?

11:22Exactly the same thing as 'List' I'm telling you in a very easy manner

11:25Exactly the same thing...

11:27...Except they are immutable. Immutable means they cannot be changed

11:31Now people confuses a lot in mutable & immutable

11:35I'm telling you with my experience many people says

11:38"Bro we are not able to remember whether we can change mutable or immutable"

11:45We've a problem with that

11:46Let me tell you how you can remember

11:49Let's suppose if it is mutable

11:51You might have studied about 'Mutation'

11:53'Mutation' basically means the occurrence of changes

11:56For eg. There's a theory which explains that in the early ages Humans used to have tails

12:00Then there were mutations, after that the tail of the humans was lost

12:05This is what scientists say

12:07I'm not teaching Biology here I'm just telling you that 'Mutation' means the occurrence of changes

12:13If you've studied Genetic Algorithm

12:16If you've studies even a little bit of Biology in Class 10th or 9th. Come on we all did

12:21'Mutation' means changes

12:23That we used to be Monkey at first

12:25Then we evaluated to Humans This is called Mutations

12:28So 'Mutable' means changes can be made

12:31'Immutable' means changes cannot be made

12:34This is how you can remember

12:36It's the easy way to remember

12:37It's possible that you remember it easily

12:38And after listening to me you can say "Come on bro! I remember it easily"

12:42I was just telling this for the people who hardly remembers it

12:45Now look,

12:47I've made a list "List the collection of items"

12:50And the 'Tuple' is also the same "List the collection of items"

12:52Except the fact that you cannot change it

12:56But if you try to do so...

12:58So it'll throw an error

12:59And "How can we change it" and all the other stuff we'll leave that for the video related to 'Tuple'

13:04I won't tell you that right now

13:05Then there comes another 'Data Type' "Mapped data: Dict"

13:09What's this? You must have a dictionary at home

13:11No?

13:12No problem! But you definitely know what dictionary is.

13:15Dictionary is the collection of key-value pairs

13:19You want to know the meaning of "Abandon"

13:21'Abandon' is a key and there'll be its value in dictionary

13:24You want to now the meaning of 'Food'

13:26'Food' is a key there'll be its value in dictionary

13:29We all know what 'Food' is

13:31Now another one... Let's suppose you want to find the meaning of...

13:34I don't remember any complex word right now. Let's say 'Mutable' you want to see it's meaning

13:37There'll be its value, meaning of "Mutable" will be written in dictionary

13:41So these are key-value pairs

13:43In form of Key-Value pairs, I can store anything

13:47In form of Key-Value pairs, I can also store...

13:50That...

13:51Marks of every student

13:53"Name of the student"

13:54And "His/Her marks"

13:56We can store this information too

13:59I just want to tell you

14:00Now let's move here...

14:02And look..

14:03I've written "dict1 ={"name":"Sakshi", "age":20, "canVote":True}

14:07So it'll print like this... Let me show you

14:09Name is 'Sakshi'

14:10Age is 20 canVote is 'True'

14:12I'll tell more about dictionary in the upcoming videos

14:14For now just understand that dictionary is a mapped data

14:17We have mapped one thing from another

14:19For eg. Name = Sakshi Marks = .....

14:22Whether she can vote or not...

14:24And if she is a good girl or not...

14:27How's she at her studies

14:29How much she scores...

14:31About her behaviour

14:35Is she a disciplinarian or not

14:37Are you getting my point? You just have to add these here

14:40And...

14:42Your dictionary will be ready

14:43So I hope you've understood the topics 'Tuple' 'List' & 'Dictionary'

14:47Now I'd like to say something

14:49This may blow your mind

14:53Your mind will be blown after listening to this

14:55May be not! May be

14:57But you'll put your thinking cap on

15:00Everything in Python is an 'Object'

15:03Yes! Everything

15:04'Dictionary' is an object

15:06If you create a 'Dictionary', so it is an object

15:09If you create a 'Boolean', so it is an object

15:11'Integer' is an object of class 'Int'

15:14That's why when we printed it, we saw that...

15:19Look here, at the top

15:22" The type of a is <class 'complex' "

15:24So why is it referring it as 'Class'

15:26It's the 'Object' of this class

15:28Now you'll say "What is 'Class'? What are you saying 'Class' 'Object'....

15:33I'll explain everything in the upcoming videos

15:35I'll explain everything when we'll move to the object oriented programming

15:38For now just remember my words...

15:40"Everything in Python is an 'Object' "

15:42Just remember this

15:45But if you'll remember this thing so I'll remind you

15:48But for now just forget this

15:50I didn't say a word about this to you

15:54When we'll be on the video of "Classes & Objects" then you must remember this...

15:57That I told you "Everything in Python is an 'Object' "

15:59I'll explain this in that video

16:01For now just grasp the concept of 'Data Type'

16:03There are different kind of 'Data Type'

16:05Study this efficiently

16:08That's it for this video and I hope you had fun in it

16:11And if you haven't accessed the Python Play-list yet

16:13So make sure to access it

16:15Bookmark it by clicking here just like me and save it by clicking here

Recently added transcripts

Browse the whole transcript library

This transcript was generated from the captions YouTube publishes for this video. Get the transcript of any YouTube video atfreeyoutubetranscribe.com, free, unlimited, no sign-up.