Like any human language, all programming languages have syntax and semantics.
Syntax refers to the rules of the programming language.
semantics is related to the meaning of elements of a program and what they do.
If a program violates any of the syntax rules of a language, the compiler or the interpreter produces an error message called syntax error.
A program can have no syntax error and get executed properly but can still behave in a way different from what it is intended to This kind of error is known as logic error
logic error is associated with the semantics of a language.
Since compilers or interpreters do not catch logic errors, they are far more difficult to identify and fix than syntax errors.
Python is one of the popular high-level programming languages in use today.
python is considered a much easier language to learn and one of the main reasons why it is a widely chosen language for teaching programming to those who are new to programming.
Python has a free IDLE.
IDLE stands for Integrated Development and Learning Environment.
To write Python codes, the interactive interpreter or the text editor of the IDLE can be used.
The interactive interpreter is used to write one line of Python code at a time and is less convenient to write and execute a large number of codes
in text editor any number of codes can be written and get executed with a single command.
The Interactive Interpreter contains a Python shell
python shell is a textual user interface used to work with the Python language.
The Interactive Interpreter is displayed when the IDLE is opened.
The >>> is where codes are written and is called the prompt
To display something on the screen, the print() function is used in Python
IDLE uses different types of colors for the differentelements of a Python code to make them easily distinguishable.
-> outputs - blue -> functions - purple -> strings - green
string is a sequence of characters placed under quotation marks
The code that is kept in such files is known as a script.
A file that keeps Python scripts is saved with the .py extension and is called a script file
The prompt appears only when code is written in the interactive interpreter, not inthe text editor.
While only one line of code is written and executed in the interactive interpreter, as many lines of code as required can be written in the text editor.
Before the script is run the script has to be saved with the .py extension by selecting the “save” option from the “file” menu in the text editor.
To execute the script, the “Run Module” option from the “Run” Menu should be selected.
After the script is executed, the output is displayed in the IDLE shell/interactive interpreter in a format
Though there are four statements in the script, only one output is shown in the IDLE shell. This is because it is only the last statement that produces an output
The * is multiplication operator in Python and ** is exponentiation operator
the interpreter did not generate any error and simply displayed the incorrect output. This is a logic error
Variables are computer memory locations.
variables are the means to store data in computer memory.
a variable is created along with its value.
Values are assigned to variables using the assignment (=) operator, which has two operands.
The operand to the left of the operator is always a variable while the operand to the right of the operator is either a literal value or any other type of expression.
a variable can be assigned to another value than the one it was previously assigned to.
The name that is given to variables is called an identifier.
Identifiers are a string of one or more characters and have to conform to some rules in Python to be considered valid.