1
00:00:00,000 --> 00:00:05,990
Assignments in Python are handled with the assignment operator, which is the Equal sign.

2
00:00:06,000 --> 00:00:10,990
Let's go ahead and make a working copy of syntax.py.

3
00:00:11,000 --> 00:00:13,990
I'll call it syntax-working.py.

4
00:00:14,000 --> 00:00:18,990
And we'll open that working copy, and we'll go ahead and create an assignment.

5
00:00:19,000 --> 00:00:23,990
So I'll have a variable called a, and I will assign it the value 1.

6
00:00:24,000 --> 00:00:30,990
Now what this does in Python is it actually defines the variable a, and it

7
00:00:31,000 --> 00:00:36,990
creates an integer type variable, and it puts the value 1 in it.

8
00:00:37,000 --> 00:00:40,990
And so in the print statement, I can print a.

9
00:00:41,000 --> 00:00:48,990
And if I go ahead and save this and run it, we'll see that we get the value 1 printed.

10
00:00:49,000 --> 00:00:57,990
If instead I were to put a string there, say "one" spelled out, run that then

11
00:00:58,000 --> 00:00:58,990
we get a one here.

12
00:00:59,000 --> 00:01:05,990
We can look at the type of the variable that was created by using the type function.

13
00:01:06,000 --> 00:01:08,990
And so this will print the type and the value.

14
00:01:09,000 --> 00:01:09,990
Save that and run it.

15
00:01:10,000 --> 00:01:13,990
See that that's a Class String, it's the type.

16
00:01:14,000 --> 00:01:18,990
In fact everything in Python is an object, and objects have classes, and so the

17
00:01:19,000 --> 00:01:23,990
type of a thing is typically the name of the class.

18
00:01:24,000 --> 00:01:29,990
And so if I make this a number again and save that and run it, we'll see that we

19
00:01:30,000 --> 00:01:32,990
get a variable of the <class 'int'>.

20
00:01:33,000 --> 00:01:38,990
So if a variable has not been assigned before, then the assignment operator

21
00:01:39,000 --> 00:01:41,990
actually creates the object.

22
00:01:42,000 --> 00:01:45,990
And it creates it of the appropriate type, or the appropriate class.

23
00:01:46,000 --> 00:01:54,990
You can assign multiple objects at the same time. You can say a, b = 0, 1, and

24
00:01:55,000 --> 00:02:02,990
then if I print(a, b), then I'll get both of those values, the 0 and the 1.

25
00:02:03,000 --> 00:02:12,990
Interestingly, you can even do something like this, where you're actually

26
00:02:13,000 --> 00:02:13,990
swapping these values.

27
00:02:14,000 --> 00:02:18,990
You can use the same variables on the right and the left-hand side of the Equal

28
00:02:19,000 --> 00:02:22,990
sign, and you can pretty much do this safely under most circumstances.

29
00:02:23,000 --> 00:02:29,990
So here we'll get a 1 and 0 when we run this, 1, 0.

30
00:02:30,000 --> 00:02:34,990
There are some types of objects in Python that are sets of values, or sequences

31
00:02:35,000 --> 00:02:38,990
of values, called lists, and tuples, and things like that.

32
00:02:39,000 --> 00:02:50,990
For example, if we say a = (1, 2, 3, 4, 5), by putting them in the parentheses,

33
00:02:51,000 --> 00:02:53,990
this makes this into a tuple.

34
00:02:54,000 --> 00:02:57,990
And if we save this and run it, you see that we get all of those values.

35
00:02:58,000 --> 00:03:01,990
Now, when you use print on an aggregate type, on a set, or a tuple, or something

36
00:03:02,000 --> 00:03:06,990
like that, it actually tries to print it in a form that would be acceptable

37
00:03:07,000 --> 00:03:10,990
syntax in Python for creating that object.

38
00:03:11,000 --> 00:03:15,990
And so for example, another aggregate type is the list, which has square brackets.

39
00:03:16,000 --> 00:03:22,990
And if I define it like that, then the print statement will print it like that.

40
00:03:23,000 --> 00:03:29,990
So the assignment operator is used for assigning a value in Python,

41
00:03:30,000 --> 00:03:40,000
and it will also create an object if that object has not already been created.

