Skip to content

Commit 72d0591

Browse files
authored
Update Comments.md
1 parent 5229c42 commit 72d0591

1 file changed

Lines changed: 58 additions & 39 deletions

File tree

Basic/Comments.md

Lines changed: 58 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,76 @@
1-
## Comments :thought_balloon:
1+
## Indentation
22

3-
### Basic of Comments :bell:
4-
5-
- Comments :thought_balloon: are very important while writing a program.
6-
- It describes what's going on inside a program so that a person looking at the source code does not have a hard time figuring it out.
73

8-
For comments there are two options
4+
### Basic of Indentation
5+
**indentation** concepts which play a vital role in python app development
96

10-
#### 1.Single line comment :skull:
11-
- we use the hash (**#**) symbol to start writing a comment.
12-
- Python Interpreter ignores comment.
7+
- One of the most distinctive features of Python is its use of indentation to mark blocks of code.
8+
- Other some languages such as c and c++ uses curly braces(**{}**) to differentiate block of code
9+
- But in python, we use indentation to differentiate block of code (basically tab of some active space)
10+
- we use a colon as the starting of code block and afterwords all code block will be placed.
11+
- Leading whitespace (spaces and tabs) at the beginning of a logical line is used to compute the indentation level of the line, which in turn is used to determine the grouping of statements.
12+
- A code block (body of a function, loop, etc.) starts with indentation and ends with the first unindented line.
13+
- The amount of indentation is up to you, but it must be consistent throughout that block.
1314

14-
For example:
15-
```python
16-
#this is first comment
17-
#this is second comment
18-
a=5 #code with comment
15+
### For example:
16+
consider if loop
17+
In C Programing :scroll::
18+
```python
19+
if(conditions) {
20+
#main code
21+
}
1922
```
23+
In python Programing:
2024

21-
#### 2.Multi line comment :dolls:
22-
- Use triple quotes, either **'''** or **"""**. For multicommenting.
23-
- These triple quotes are generally used for multi-line strings.
24-
But they can be used as multi-line comment as well. Unless they are not docstrings,
25-
they do not generate any extra code.
25+
With Brackets
26+
```python
27+
if(conditions) :
28+
#Write Your Main Code Here
29+
```
2630

27-
For Example:
31+
without Brackets
2832
```python
29-
''' this is multi line comment
30-
Second line comment
31-
Third line comment
32-
Fourth line '''
33+
if conditions:
34+
#Write Your Main Code Here
3335
```
3436

35-
Or
37+
### How can we write code block in one line
38+
- Indentation can be ignored in line with continuation.
39+
- But it's a good idea to always indent. It makes the code more readable.
40+
Example:
41+
with Brackets
3642
```python
37-
"""this is multi line comment
38-
Second line comment
39-
Third line comment
40-
Fourth line """
43+
if(conditions) :#main code
4144
```
4245

46+
Without Brackets
47+
```python
48+
if conditions: #Write Your Main Code Here
49+
```
4350

44-
### Is this possible to assign multiple lines :page_with_curl: to a single variable
51+
### Wrong Spaces Inside Program Create Indentation Error.
4552

46-
yes you can use in following ways:
53+
Consider following code block
4754
```python
48-
myvar= """this is multi line comment
49-
Second line comment
50-
Third line comment
51-
Fourth line """
52-
53-
#for print result
54-
print(myvar)
55+
if(1==1) :
56+
print("First line")
57+
print("second line")
5558
```
5659

57-
**Note:-** multi line comments are also used to create doc string for function or class
60+
Incorrect indentation will result into
61+
```python
62+
IndentationError: unindent does not match any outer indentation level
63+
```
64+
65+
Correct Solution
66+
```python
67+
if 1==1 :
68+
print("First line")
69+
print("second line")
70+
```
71+
72+
Output
73+
```
74+
First line
75+
second line
76+
```

0 commit comments

Comments
 (0)