1
00:00:00,120 --> 00:00:05,730
So I have explained to you already in the previous lecture that Python handles data types in a very

2
00:00:05,730 --> 00:00:06,870
convenient manner.

3
00:00:07,500 --> 00:00:13,380
For example, if we divide two integer numbers, it will give us a floating point number, which is

4
00:00:13,380 --> 00:00:17,220
very convenient because then we don't have to be careful what we're doing.

5
00:00:17,760 --> 00:00:23,310
So we can just write whatever we want to do, and it gives us the correct results.

6
00:00:24,240 --> 00:00:30,920
So let's discuss a bit more the different data types and especially who will start with the numbers.

7
00:00:30,930 --> 00:00:34,590
So we will discuss integer float and complex data types.

8
00:00:35,640 --> 00:00:41,460
So for example, when we write five, then of course it will be a five and integer number.

9
00:00:41,760 --> 00:00:48,390
But if we write 5.0, even though it's mathematically speaking exactly the same thing, the output will

10
00:00:48,390 --> 00:00:49,830
be 5.0.

11
00:00:50,520 --> 00:00:53,520
And you can see that both of these have different data types.

12
00:00:54,150 --> 00:00:59,580
So the five is an integer number and the 5.0 is a floating point number.

13
00:01:00,540 --> 00:01:04,709
So as I mentioned, there is really no need to define the data type.

14
00:01:05,220 --> 00:01:12,600
Python is really handy and using or in dealing with these data types in a very convenient manner, and

15
00:01:12,600 --> 00:01:14,100
it does everything automatically.

16
00:01:14,880 --> 00:01:20,460
So we can, for example, just add these two numbers five integer and floating point five, and the

17
00:01:20,460 --> 00:01:22,620
result will be a floating point ten.

18
00:01:23,940 --> 00:01:30,420
So if for whatever reason, you want to convert different data types from one to another.

19
00:01:30,720 --> 00:01:31,950
This is, of course, possible.

20
00:01:32,460 --> 00:01:38,280
For example, this could be useful for creating some output where the result would be just 10.

21
00:01:38,550 --> 00:01:43,610
And instead, the output would normally be expressed as ten point zero.

22
00:01:44,280 --> 00:01:50,760
So then in this case, you could, for example, turn this into an integer number so we can turn integer

23
00:01:50,760 --> 00:01:55,440
numbers into floating points numbers and we can do it the other way around.

24
00:01:56,490 --> 00:02:03,810
And here you must be a bit careful because if you try to transform a floating point number that is not

25
00:02:04,020 --> 00:02:08,580
dot zero into an integer number, then of course you will lose some information.

26
00:02:08,580 --> 00:02:09,660
You will make a small error.

27
00:02:10,470 --> 00:02:18,180
So this will not really round the number, but we'll just cut off the floating point number, so all

28
00:02:18,180 --> 00:02:21,210
of the digits after the comma or the dots.

29
00:02:22,650 --> 00:02:26,580
So in this case, int of 5.9 is just five.

30
00:02:27,390 --> 00:02:33,990
If you want to really do mathematical around operation, then you're right around five point nine and

31
00:02:33,990 --> 00:02:35,550
then it will give you six.

32
00:02:37,110 --> 00:02:44,940
So now we know about integer data type and float data type and something that's also very important,

33
00:02:44,940 --> 00:02:48,840
especially for physics programming is complex numbers.

34
00:02:49,560 --> 00:02:58,440
So the complex data type, so I hope you know this, that a complex number consists out of a real part

35
00:02:58,440 --> 00:03:06,480
and an imaginary part, and the imaginary part is just a floating point number, a real number multiplied

36
00:03:06,480 --> 00:03:08,730
by the imaginary unit.

37
00:03:09,390 --> 00:03:12,060
So in mathematics, this unit is called Are you?

38
00:03:12,600 --> 00:03:14,730
But in Python, it's called Jane.

39
00:03:15,630 --> 00:03:23,550
So if you're just right, Jane, there's a bit of a problem because J is not defined, it just means

40
00:03:23,940 --> 00:03:27,000
could mean a variable that we could define, for example, J for one.

41
00:03:27,870 --> 00:03:34,110
So if you want to have the imaginary unit I or in Python J and you must write something like one J.

42
00:03:34,980 --> 00:03:37,140
Or you must write something like two g.

43
00:03:38,550 --> 00:03:39,990
So special property.

44
00:03:40,470 --> 00:03:42,150
Sorry, I didn't take so long.

45
00:03:43,140 --> 00:03:49,560
So the special property of this imaginary unit is that the square of this number is negative.

46
00:03:49,560 --> 00:03:50,430
It's minus one.

47
00:03:51,810 --> 00:03:58,710
So if you run this, you will see the result is minus one plus zero g, so basically just minus one.

48
00:03:59,790 --> 00:04:05,130
So this allows us to calculate the square root of a negative number.

49
00:04:05,880 --> 00:04:11,280
So, for example, we could write and, um, pi square root of minus one.

50
00:04:12,810 --> 00:04:20,130
Um, and it tells us there is an invalid number, but what we could do is something like this

51
00:04:23,370 --> 00:04:30,630
because then we tell our computer or our Python program that we want to consider complex numbers.

52
00:04:30,990 --> 00:04:39,600
So in this case, there's minus one has the data type of a complex so we can calculate the square root,

53
00:04:39,690 --> 00:04:41,630
which will then be J.

54
00:04:41,880 --> 00:04:46,570
Or in mathematical language, the imaginary unit I sent.

55
00:04:46,570 --> 00:04:54,000
The type of such a complex number is, of course, complex, and we can, of course, to all the basic

56
00:04:54,000 --> 00:04:56,850
mathematical operations, for example, multiplication.

57
00:04:57,210 --> 00:04:59,910
So if we multiply these two complex numbers here.

58
00:05:00,250 --> 00:05:07,120
We get another complex number, and the result will be the real part is three times one, which is three.

59
00:05:07,570 --> 00:05:13,900
And then the other contribution to the real part would be five eye times too high, which would be 10.

60
00:05:13,900 --> 00:05:14,590
I squirt.

61
00:05:14,800 --> 00:05:16,560
So I squared, it's minus one.

62
00:05:16,570 --> 00:05:17,650
So this is minus 10.

63
00:05:17,890 --> 00:05:20,230
So we have three minus 10 as minus seven.

64
00:05:20,800 --> 00:05:25,090
And then for the imaginary part, we have two terms.

65
00:05:25,420 --> 00:05:27,700
So we have five times one, which is five.

66
00:05:28,270 --> 00:05:31,450
And we have three times too high, which is six I.

67
00:05:31,480 --> 00:05:34,450
So we have five plus six I, which is 11 I.

68
00:05:35,470 --> 00:05:42,760
So you see, we can really do all of the operations using complex numbers, but also you see that sometimes

69
00:05:42,760 --> 00:05:51,730
we must be careful because here we had the problem when we wrote and p square root of minus one gave

70
00:05:51,730 --> 00:05:52,420
us a mistake.

71
00:05:52,780 --> 00:05:56,950
But if we write this as a complex number, then it works.

72
00:05:57,310 --> 00:05:58,570
So let's see if this works.

73
00:06:02,910 --> 00:06:04,470
Oh, sorry, forgot the brackets.

74
00:06:04,800 --> 00:06:05,760
So now it works.

75
00:06:06,290 --> 00:06:12,360
So if we turn the real number or the integer number into a complex number, then you can use the square

76
00:06:12,360 --> 00:06:12,930
root command.

77
00:06:13,710 --> 00:06:18,690
So sometimes when using complex numbers, you must be a bit careful with the data types.

78
00:06:19,050 --> 00:06:25,260
But most of the times Python will manage all of these things just fine, and you don't need to watch

79
00:06:25,260 --> 00:06:29,070
out for some problems like you have to do in other programming languages.

