Python Syntax
Like any other programming language, Python has a set of rules. These rules define how to write a program in that language. It also explains how the interpreter understands the code. These rules are set on the runtime system and followed by the person writing the code.
Comments
A comment is a piece of text within a program that is not executed. It can be used to provide additional information to aid in understanding the code.
The # character is used to start a comment and it continues until the end of the line.
Arithmetic Operations
Python supports different types of arithmetic operations that can be performed on literal numbers, variables, or some combination. The primary arithmetic operators are:
​
-
+ for addition
-
- for subtraction
-
* for multiplication
-
/ for division
-
% for modulus (returns the remainder)
-
** for exponentiation
Plus-Equals Operator +=
The plus-equals operator += provides a convenient way to add a value to an existing variable and assign the new value back to the same variable. In the case where the variable and the value are strings, this operator performs string concatenation instead of addition.
​
The operation is performed in-place, meaning that any other variable which points to the variable being updated will also be updated.
Variables
A variable is used to store data that will be used by the program. This data can be a number, a string, a Boolean, a list or some other data type. Every variable has a name which can consist of letters, numbers, and the underscore character _.
The equal sign = is used to assign a value to a variable. After the initial assignment is made, the value of a variable can be updated to new values as needed.
Print () function
The print() function is used to output text, numbers, or other printable information to the console.
​
It takes one or more arguments and will output each of the arguments to the console separated by a space. If no arguments are provided, the print() function will output a blank line.