Beginner Python Concepts
a-Rye
41.4K views
Comments
Comments are very useful in programming. If you're coding for work or to be published, you'll want to explain your code with comments. You can also use comments in debugging to investigate your code further.
# This is a single line comment. Any line that starts with a # will be seen as a comment by the compiler / interpreter / computer.
'''
This
is
a
multi
line
comment
'''
"""
This
is
also
a
multi
line
comment
"""
# It gets a weird value here, still not sure why?
Disabling parts of your code
Sometimes, you just want a part of your code to stop temporarily. I often find myself doing this when trying to optimize my code or when trying to single out a corner case in my code.
Let's take that mass of code from the previous page and try looking at each piece individually.
Try "turning pieces on and off again"!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
print("Hello! " * 3)
# print("For the rest of the examples, let's declare a String variable to use")
test_string = "Hello World, but now our new string!"
print("Try slicing different parts of the string")
print(test_string[1:6])
# print("Print every other letter")
# print(test_string[::2])
# print("Reverse the string")
# print(test_string[::-1])
# print("Print single char at a certain index")
# print(test_string[0])
# print("This also works backwards with a negative index")
# print(test_string[-1])
# print(test_string[-5])
print("Set the start point as the fifth character from the end")
print(test_string[-5:])
print(test_string[-10:-3])
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.