You are on page 1of 3

WEBVTT

1
00:00:04.000 --> 00:00:08.000
In terms of typing, programming languages fall into two categories,

2
00:00:08.000 --> 00:00:12.000
static languages, like C++, C# and

3
00:00:12.000 --> 00:00:16.000
Java, and Dynamic languages like JavaScript, Ruby

4
00:00:16.000 --> 00:00:20.000
and Python. In static languages, when declaring a variable

5
00:00:20.000 --> 00:00:24.000
we need to specify it's type. For example, in C#

6
00:00:24.000 --> 00:00:28.000
when declaring this variable we need to set it's type to an integer.

7
00:00:28.000 --> 00:00:32.000
So, with this the type of this variable will always be

8
00:00:32.000 --> 00:00:36.000
an integer, when we compile this program our compiler knows that students count

9
00:00:36.000 --> 00:00:40.000
is an integer, so if we accidentally try to set it to

10
00:00:40.000 --> 00:00:44.000
let's say a boolean later on the compiler will

11
00:00:44.000 --> 00:00:48.000
complain. This is how static languages work. In

12
00:00:48.000 --> 00:00:52.000
dynamic languages like JavaScript and Python, we don't have this behavior.

13
00:00:52.000 --> 00:00:56.000
So, we don't set a type when defining

14
00:00:56.000 --> 00:01:00.000
a variable, we just define a variable by setting it to a value.

15
00:01:00.000 --> 00:01:04.000
So in dynamic languages the type of the variable is determined

16
00:01:04.000 --> 00:01:08.000
at run time. Now here if you hover the mouse over

17
00:01:08.000 --> 00:01:12.000
students count you will see this is an integer, so when

18
00:01:12.000 --> 00:01:16.000
working on a large, complex program, when you want to know the type of variable

19
00:01:16.000 --> 00:01:20.000
we can simply hover your mouse over it. We also have this built in

20
00:01:20.000 --> 00:01:24.000
function called type, you can pass a variable

21
00:01:24.000 --> 00:01:28.000
or object to it, like students count, and then

22
00:01:28.000 --> 00:01:32.000
print this on the console.

23
00:01:32.000 --> 00:01:36.000
So, let's run this program. You can see this type of students count

24
00:01:36.000 --> 00:01:40.000
is a class of integer. What is this? Python

25
00:01:40.000 --> 00:01:44.000
is an object oriented language, so here we have the concept of classes,

26
00:01:44.000 --> 00:01:48.000
if you're not familiar with classes, don't worry, I'm going to talk about them in
detail

27
00:01:48.000 --> 00:01:52.000
later in the course. All I want you to know now

28
00:01:52.000 --> 00:01:56.000
is that in Python, we have a class called int that represents

29
00:01:56.000 --> 00:02:00.000
integers. So all integers are instances
30
00:02:00.000 --> 00:02:04.000
of this class. Let's take a look at a few more examples.

31
00:02:04.000 --> 00:02:08.000
So here in this interactive shell. Let's take a look at

32
00:02:08.000 --> 00:02:12.000
type of a float. Once again, it's a class called

33
00:02:12.000 --> 00:02:16.000
float. Let's look at type of a boolean

34
00:02:16.000 --> 00:02:20.000
this is also a class called

35
00:02:20.000 --> 00:02:24.000
bool. But let's look at type of a string, that's a class called

36
00:02:24.000 --> 00:02:28.000
str. So here's the takeaway. Python is

37
00:02:28.000 --> 00:02:32.000
a dynamic language, which means the type of variables are determined

38
00:02:32.000 --> 00:02:36.000
at runtime as opposed to compile time.

You might also like