1 00:00:00,000 --> 00:00:01,500 [no audio] 2 00:00:01,510 --> 00:00:02,500 Hi friends, here 3 00:00:02,500 --> 00:00:06,100 we are going to discuss about indentation in Python. 4 00:00:07,300 --> 00:00:08,700 Right. Let me start that. 5 00:00:09,600 --> 00:00:12,500 First of all, what is an indent? 6 00:00:13,400 --> 00:00:15,700 See indent is nothing but a space. 7 00:00:17,500 --> 00:00:22,100 So guys, if you know some other languages like C, C++, Java, 8 00:00:22,200 --> 00:00:24,600 or some shell scripts, right, 9 00:00:26,200 --> 00:00:29,000 let's say suppose C language, 10 00:00:29,900 --> 00:00:33,900 so in C language to represent some block of code 11 00:00:33,900 --> 00:00:37,800 we are using curly braces. Now, the lines which are there between 12 00:00:37,800 --> 00:00:43,000 these two curly braces are a block. The lines which are there 13 00:00:43,000 --> 00:00:44,900 between these two curly braces, 14 00:00:44,900 --> 00:00:50,100 this one and this one, is one block. Now to represent some set 15 00:00:50,100 --> 00:00:54,000 of lines as a separate code, as a separate block of code 16 00:00:54,000 --> 00:00:55,500 we are using curly braces there. 17 00:00:56,500 --> 00:01:00,600 But in your Python you don't have something like curly braces 18 00:01:00,600 --> 00:01:03,300 to represent a block of code. 19 00:01:03,500 --> 00:01:04,599 Now instead of that 20 00:01:05,099 --> 00:01:07,000 we are using here indentations. 21 00:01:07,200 --> 00:01:11,800 We are using some space to represent a block of code, right. 22 00:01:12,100 --> 00:01:15,800 So indentations are used to represent a block of code. 23 00:01:15,800 --> 00:01:17,600 [no audio] 24 00:01:17,600 --> 00:01:19,800 Right. Let me give you simple example. 25 00:01:21,000 --> 00:01:25,100 So as of now, I don't know about Python, but just observe 26 00:01:25,100 --> 00:01:26,900 the some code. 27 00:01:27,800 --> 00:01:29,400 Let me write simple code. 28 00:01:29,400 --> 00:01:46,100 [no audio] 29 00:01:46,100 --> 00:01:49,100 So here I'm opening a program, a script called 30 00:01:49,100 --> 00:01:52,400 'indentations_usage.py', right. Very first line 31 00:01:52,400 --> 00:01:59,600 I am writing simply 'print("This is about indentations")'. Right, 32 00:01:59,600 --> 00:02:01,000 simply you are printing some string. 33 00:02:01,600 --> 00:02:08,500 Now what I am doing is 'if 3 > 1 then', 34 00:02:09,600 --> 00:02:12,800 I want to execute some two lines - 'print( 35 00:02:14,000 --> 00:02:21,100 "using if condition"), 'print("we are checking"). 36 00:02:21,100 --> 00:02:23,800 [no audio] 37 00:02:23,800 --> 00:02:26,300 "we are comparing 38 00:02:26,300 --> 00:02:28,500 [no audio] 39 00:02:28,500 --> 00:02:30,200 3 and 1")', that's it. 40 00:02:31,300 --> 00:02:32,300 Now guys see that 41 00:02:32,800 --> 00:02:35,200 I am giving some space for these two lines. 42 00:02:36,700 --> 00:02:39,800 Now, these two lines are a block of code. 43 00:02:41,400 --> 00:02:45,300 These two lines are a block of code, and this block of code 44 00:02:45,300 --> 00:02:46,300 is under this line. 45 00:02:47,000 --> 00:02:51,000 So after this line I am giving some space, equal space for 46 00:02:51,000 --> 00:02:54,700 all lines. Then these lines, even you can write 100 lines 47 00:02:54,700 --> 00:02:59,200 also with equal space. Now all 100 lines are there under this line. 48 00:02:59,500 --> 00:03:01,800 Because after this line only we are giving spaces, 49 00:03:02,100 --> 00:03:04,900 that's why all these lines are there under this line, whatever 50 00:03:04,900 --> 00:03:06,000 it may be. As of now 51 00:03:06,000 --> 00:03:09,200 we don't know about your Python, right. Just observe that. 52 00:03:09,200 --> 00:03:11,500 [no audio] 53 00:03:11,500 --> 00:03:13,900 Now these two lines are called block of code, 54 00:03:13,900 --> 00:03:16,000 and this line is there under this line. 55 00:03:16,000 --> 00:03:18,000 Now, let me save it and run this. 56 00:03:18,000 --> 00:03:22,700 [no audio] 57 00:03:22,700 --> 00:03:23,700 Oh, sorry. 58 00:03:23,700 --> 00:03:27,300 [no audio] 59 00:03:27,300 --> 00:03:28,800 Right. Now I am running this. 60 00:03:29,800 --> 00:03:31,800 Okay. Simply 'python', 61 00:03:33,200 --> 00:03:34,500 your script name. 62 00:03:35,900 --> 00:03:37,900 Right. You're getting some output, right. 63 00:03:37,900 --> 00:03:39,700 Just see once again your code. 64 00:03:39,700 --> 00:03:41,600 [no audio] 65 00:03:41,600 --> 00:03:45,800 Now, this is called indentation, right. Now, 66 00:03:47,000 --> 00:03:49,000 the amount of indentation is up to you, 67 00:03:50,300 --> 00:03:54,400 but it must be consistent throughout that block. See that. 68 00:03:55,600 --> 00:03:58,800 I have given same space for first line and second line. In 69 00:03:58,800 --> 00:04:08,100 case by mistake if I give some extra space or some less 70 00:04:08,100 --> 00:04:12,100 space, right, and try to run your script, and see the output 71 00:04:12,100 --> 00:04:12,800 what you are getting. 72 00:04:12,800 --> 00:04:16,300 [no audio] 73 00:04:16,300 --> 00:04:20,800 'IndentationError: unexpected indent'. Unnecessarily you're 74 00:04:20,800 --> 00:04:24,500 providing some space, right? 75 00:04:24,700 --> 00:04:28,200 So guys whenever if you want to provide a space, right, 76 00:04:28,200 --> 00:04:31,100 so before that line you should have some condition, or some 77 00:04:31,100 --> 00:04:32,400 function name, something like that. 78 00:04:32,700 --> 00:04:36,300 As of now we don't know that's why just assume that for each and 79 00:04:36,300 --> 00:04:40,600 every line you should have same space. Unnecessarily don't provide space. 80 00:04:41,800 --> 00:04:43,400 right, not only here. Now, 81 00:04:43,400 --> 00:04:44,700 let me recheck it. First, 82 00:04:44,700 --> 00:04:46,900 [no audio] 83 00:04:46,900 --> 00:04:48,400 I'm running. It's working. 84 00:04:48,700 --> 00:04:51,200 Now, what I am doing is for very first line 85 00:04:51,300 --> 00:04:54,000 I am going to provide a space. Very first line is some 'print' 86 00:04:54,000 --> 00:04:55,100 statement. For that 87 00:04:55,100 --> 00:04:56,300 I'm giving some space. 88 00:04:57,600 --> 00:05:00,500 If I give some space, and if I run, observe that 89 00:05:01,900 --> 00:05:07,200 you are getting an error like again, 'IndentationError: unexpected indent' 90 00:05:07,200 --> 00:05:10,200 Unnecessarily you're providing space for line #1. 91 00:05:10,200 --> 00:05:12,900 [no audio] 92 00:05:12,900 --> 00:05:19,100 Right. So to provide some space before starting your line, right, 93 00:05:19,100 --> 00:05:20,200 before that line 94 00:05:20,200 --> 00:05:23,500 you should have some logic. That logic like, with 'if' condition, 95 00:05:23,500 --> 00:05:27,200 or some function name, or some class name, something like that. 96 00:05:27,200 --> 00:05:29,600 [no audio] 97 00:05:29,600 --> 00:05:31,500 Right. Let me open your script. 98 00:05:32,600 --> 00:05:33,700 Very first line I am 99 00:05:33,700 --> 00:05:36,300 starting. If it is very first line, first of all you should 100 00:05:36,300 --> 00:05:37,400 not provide any space. 101 00:05:38,600 --> 00:05:41,000 Let me delete that space. Even 102 00:05:41,000 --> 00:05:43,500 [no audio] 103 00:05:43,500 --> 00:05:44,600 let me do one thing. 104 00:05:46,300 --> 00:05:49,500 Now forget about your block of code. Now, I'm writing something 105 00:05:49,500 --> 00:05:50,500 here, 'print'. 106 00:05:50,500 --> 00:05:53,700 [no audio] 107 00:05:53,700 --> 00:05:57,100 "we are okay with indentations". 108 00:05:57,100 --> 00:06:00,400 [no audio] 109 00:06:00,400 --> 00:06:04,500 Now for this 'print' statement, right, if I write some space 110 00:06:05,700 --> 00:06:11,200 then your Python won't accept. In case if this line is under this line, 111 00:06:11,300 --> 00:06:14,500 I mean under this block of code, then for this line 112 00:06:14,500 --> 00:06:19,100 you have to provide same length of space, but we are providing 113 00:06:19,100 --> 00:06:20,600 only one space. 114 00:06:21,900 --> 00:06:26,000 In case if this line is also under this block, then you have 115 00:06:26,000 --> 00:06:27,200 to provide same space here. 116 00:06:27,200 --> 00:06:30,700 But my assumption is there is no relation between this block 117 00:06:30,700 --> 00:06:34,100 of code and this line, and this is I am assuming this is a separate line. 118 00:06:34,500 --> 00:06:37,700 If this is a separate line, you should not provide a space first. 119 00:06:39,300 --> 00:06:41,700 If you want to provide a space, before this line you 120 00:06:41,700 --> 00:06:44,900 have to write again something, like some condition name, some 121 00:06:44,900 --> 00:06:48,300 condition, or some function name, or some class name. 122 00:06:48,300 --> 00:06:50,400 [no audio] 123 00:06:50,400 --> 00:06:54,000 Right. So as of now, we don't have anything like condition, function, 124 00:06:54,000 --> 00:06:56,900 and classes. Don't provide a space. That's it. 125 00:06:57,400 --> 00:07:01,500 So simply guys as a learner don't provide any space before 126 00:07:01,500 --> 00:07:02,500 starting your line. 127 00:07:04,500 --> 00:07:07,400 Okay. That is nothing but simply about your indentations 128 00:07:07,400 --> 00:07:08,400 of your Python. 129 00:07:08,400 --> 00:07:10,600 [no audio] 130 00:07:10,600 --> 00:07:12,500 Right. That's it. Now it's working perfectly. 131 00:07:12,500 --> 00:07:14,300 [no audio] 132 00:07:14,300 --> 00:07:16,800 So guys, final point just remember that this is very important, 133 00:07:16,800 --> 00:07:19,400 don't include an indent unnecessarily. 134 00:07:21,000 --> 00:07:22,400 Right. Okay. 135 00:07:22,600 --> 00:07:24,300 Okay. Thank you for watching this video. 136 00:07:24,300 --> 00:07:31,200 [no audio]