Learning Python Programming Language: Exercise on Print Function
In the previous video, we learned how to print something on the console using
Python. Now, let's do an exercise on the print function. We want to print three
lines exactly as shown:
First line: "First Program - Python Print Function"
Second line: "It is declared like this: print()"
Third line: "What to print"
To print this, we simply need to write the statements inside the print function.
The first line is easy, just write "First Program - Python Print Function" inside
the print function. For the second line, write "It is declared like this: print()"
inside the print function. For the third line, write "'What to print'" (with the
single quotes) inside the print function.
Once you have written the code, create a new file called "exercise1.py" and write
the code in there. Then, run the code to see the output.
Using Single Quotes vs Double Quotes
When using the print function, you can enclose the string or message in either
single quotes or double quotes. However, if you want to print single quotes within
your string, you need to be careful. For example, if you try to enclose the entire
string in single quotes and include a single quote within the string, Python will
interpret the single quote as the end of the string and give you an error. To avoid
this, you can enclose the string in double quotes and include the single quotes
within the string.
In the next video, we will discuss string manipulations and how to use them in the
print function.
Sporting exercise is an important aspect of learning theory concepts. In addition
to the theory, we also have a video coding exercise that demonstrates the concept
in action. Stay tuned for the next video. Until then, take care!
In the previous video, we learned how to print something on the console using
Python. Now, let's do an exercise on the print function. We want to print three
lines exactly as shown:
First line: "First Program - Python Print Function"
Second line: "It is declared like this: print()"
Third line: "What to print"
To print this, we simply need to write the statements inside the print function.
The first line is easy, just write "First Program - Python Print Function" inside
the print function. For the second line, write "It is declared like this: print()"
inside the print function. For the third line, write "'What to print'" (with the
single quotes) inside the print function.
Once you have written the code, create a new file called "exercise1.py" and write
the code in there. Then, run the code to see the output.
Using Single Quotes vs Double Quotes
When using the print function, you can enclose the string or message in either
single quotes or double quotes. However, if you want to print single quotes within
your string, you need to be careful. For example, if you try to enclose the entire
string in single quotes and include a single quote within the string, Python will
interpret the single quote as the end of the string and give you an error. To avoid
this, you can enclose the string in double quotes and include the single quotes
within the string.
In the next video, we will discuss string manipulations and how to use them in the
print function.
Sporting exercise is an important aspect of learning theory concepts. In addition
to the theory, we also have a video coding exercise that demonstrates the concept
in action. Stay tuned for the next video. Until then, take care!