Basic concepts in python
Comments in Python start with the hash character, #, and extend to the end of the physical line.
A comment may appear at the start of a line or following whitespace or code, but not within a string literal. A hash character within a string literal is just a hash character. Since comments are to clarify code and are not interpreted by Python, they may be omitted when typing in examples.
# this is the first comment
spam = 1 # and this is the second comment
# ... and now a third!
text = "# This is not a comment because it's inside quotes."
Let’s try some basic Python commands. Start the interpreter and wait for the python prompt, >>>.
Numbers
The equal sign (
Using (/) gives you float value of remainder using (//) gives integer value of the remainder.
In addition to
=
) is used to assign a value to a variable. Afterward, no result is displayed before the next interactive prompt. In Python, we need no to define the variable before using it. But If a variable is not “defined” (assigned a value), trying to use it will give you an errorUsing (/) gives you float value of remainder using (//) gives integer value of the remainder.
In addition to
int
and float
, Python supports other types of numbers, such as Decimal
and Fraction
. Python also has built-in support for complex numbers and uses the j
or J
suffix to indicate the imaginary part (e.g. 3+5j
).
All concepts have an example given below
- ( \ ) is used to escape quotes in a string.
- You can use raw strings by adding an
r
before the first quote it makes sure to ignore the meaning of ( \n ).
- Strings can be concatenated (glued together) with the
+
operator, and repeated with*
- Two or more strings beside each other are concatenated automatically.
All concepts have an example given below
No comments