Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,910 --> 00:00:02,050
Welcome back.
2
00:00:02,080 --> 00:00:05,770
In this video, we'll go over comments in Python.
3
00:00:08,170 --> 00:00:09,730
I am creating a new script.
4
00:00:13,850 --> 00:00:20,420
Guido van Rossum, the creator of Python, once said that code is more often read than written.
5
00:00:21,060 --> 00:00:27,120
When working with any programming language, you should include comments in the code to notate your
6
00:00:27,120 --> 00:00:27,750
work.
7
00:00:28,080 --> 00:00:35,760
This documents what certain parts of the code are for and lets other developers, you included, know
8
00:00:35,760 --> 00:00:38,970
what you intended to do when you first wrote the code.
9
00:00:39,680 --> 00:00:46,820
This is a very good practice in any programming language, and good developers make heavy use of comments.
10
00:00:47,060 --> 00:00:53,030
Without them, things can get really confusing, especially in complex projects.
11
00:00:54,340 --> 00:00:55,840
Comics in Python.
12
00:00:55,840 --> 00:01:00,850
Start with the hash character and extend to the end of the line.
13
00:01:02,040 --> 00:01:06,570
A comment may appear at the start of a line or following the code.
14
00:01:06,870 --> 00:01:12,420
Comments are for clarifying code and are not interpreted by Python.
15
00:01:12,450 --> 00:01:14,100
Let's see some examples.
16
00:01:14,820 --> 00:01:16,500
This is a comment.
17
00:01:17,280 --> 00:01:23,280
It's recommended to add a whitespace after the hash symbol for readability.
18
00:01:26,790 --> 00:01:29,610
Hash A equals five.
19
00:01:29,820 --> 00:01:32,070
This line is another comment.
20
00:01:35,530 --> 00:01:37,330
X equals nine.
21
00:01:38,290 --> 00:01:42,100
And I'm adding an inline comment here.
22
00:01:42,100 --> 00:01:45,940
I create a variable called x.
23
00:01:48,370 --> 00:01:51,580
That store's an integer.
24
00:01:55,870 --> 00:01:57,910
A hash character within a string.
25
00:01:57,910 --> 00:02:01,560
Literal is just the character, not a comment.
26
00:02:01,570 --> 00:02:10,660
For example, my star equals a hash and I'm adding a hash character within a string.
27
00:02:10,660 --> 00:02:11,320
Literal.
28
00:02:12,370 --> 00:02:13,120
This is a string.
29
00:02:13,120 --> 00:02:16,190
Literal is just a hash character.
30
00:02:16,210 --> 00:02:17,320
It's not a comment.
31
00:02:20,990 --> 00:02:27,750
In other programming languages, there are ways to comment out an entire block of code here in Python.
32
00:02:27,770 --> 00:02:32,450
If you want to comment out multiple lines, you need to prefix each line.
33
00:02:32,450 --> 00:02:35,240
You want to comment out with a hash sign.
34
00:02:37,480 --> 00:02:39,940
I'm adding a few more lines of code.
35
00:02:44,020 --> 00:02:45,130
In picture.
36
00:02:45,160 --> 00:02:52,600
After selecting the code, you want to comment out press control and for backslash.
37
00:02:54,490 --> 00:03:00,580
And it will comment out the entire block of code by commenting out each individual line of that block
38
00:03:00,580 --> 00:03:01,240
of code.
39
00:03:02,010 --> 00:03:10,020
And if you select that block of code again and press control and for backslash, it will uncomment it.
40
00:03:12,480 --> 00:03:13,980
I am pressing control.
41
00:03:13,980 --> 00:03:15,210
And for Slash.
42
00:03:17,370 --> 00:03:20,190
Sometimes you might see something like this.
43
00:03:22,400 --> 00:03:26,210
Triple quotes and some python code in between.
44
00:03:28,650 --> 00:03:30,660
X equals ten.
45
00:03:30,750 --> 00:03:31,740
Print x.
46
00:03:33,630 --> 00:03:34,770
I'm running the script.
47
00:03:36,710 --> 00:03:39,380
It didn't print the value of X.
48
00:03:39,980 --> 00:03:47,000
Even though that's not interpreted by Python and is basically like a comment, it's not actually one,
49
00:03:47,000 --> 00:03:53,600
but rather a docstring and recommendation is to not use this syntax for comments.
50
00:03:53,900 --> 00:03:59,660
Doc strings are used for documentation and we'll talk about them later in the course.
51
00:04:00,080 --> 00:04:02,250
The excel about comments in Python.
52
00:04:02,270 --> 00:04:05,070
In the next video we'll talk about constants.
53
00:04:05,090 --> 00:04:05,960
Thank you.
4510
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.