Comments
In Python, comments are employed whereby one is able to write remarks on existing code to enhance its understanding by others. Overview Figure 4 below is a diagrammatic representation of Python showing that they are not recognized by the Python interpreter. There are two types of comments: These include the single-line and multi-line formats of the two scripts.
Single-line Comments
A line comment uses the hash character (#) at the start of the whole line, and goes to the line end.
Multi-line Comments
Escape Sequences
\n: Newline
\t: Horizontal tab
\\: Backslash
\': Single quote
\": Double quote
Print Statement
The print
statement is used to display output to the console. You can print text (strings), numbers, variables, and even the results of expressions.
Basic Usage
Printing Variables
Using F-Strings (Formatted String Literals)
F-strings provide a way to embed expressions inside string literals, using curly braces {}
. They are prefixed with the letter f
.
Concatenation
You can concatenate strings using the +
operator.
Printing with Separators and End Characters
You can use the sep
and end
parameters to modify the default behavior of the print
function.
Example Program
Here's a small example program that combines these concepts:
This Python Tutorials is Absolute Beginners:
ReplyDeleteBest Python Tutorials For Beginners:
ReplyDelete