The Python interpreter is a program that interprets Python code and runs it.
You can start the interpreter by selecting on an icon or typing python on the a command line, according on your configuration.
When it starts, you should see output like this:
Figure 2.1. Python enviroment. Here I am using the default IDE.
The first three lines contain details on the interpreter as well as the operating system from which it runs, but yours may differ.
Nevertheless, make sure that the software version, which in this case is 3.4.0, starts with 3, suggesting that you are using Python 3.
The final line is a prompt, indicating that the interpreter is available for code entry. The interpreter shows the following result when you write a piece of code and press Enter:
Figure 2.2. A simple addition operation.
The first program
As tradition you would write "Hello world" as the 1st program to run on python like every other beginner !!
Figure 2.3. Demonstation of 'Hello world'.
You can also print output with print statement :
Figure 2.4. A simple print statement.
On the screen, it shows the outcome. The result in this case is the phrase "Hello, World!". The quotation marks in the program indicate the start and end of the text to be displayed. Here in the final result the quotation marks are not visible.
Arithmetic operators
Operators are special symbols in Python which
depict computations such as arithmetic operations.
As shown in the instances below, the operators +, -, and * operate
addition, subtraction, and multiplication.
Figure 2.5. Simple mathematical operations.
Exponentiation is performed by the operator **, which raises a number to a power:
Figure 2.6. Performing exponent operation.
In other languages, "^" symbol would be used for exponentiation; nevertheless, in Python, it is a bitwise operator known as XOR.
Figure 2.7. XOR operation.
Values and types
A value, like a letter or a number, is one of the fundamental things that a program works with. Up to this point, we've already seen values 2, 42.0, and 'Hello, World!'
These values are classified as follows:
The number 2 is an integer.
The number 42.0 is a floating-point number, as well as the phrase 'Hello, World!'.
'Hello, World!' is a string, so named since the letters in it are stitched together.
If you are unsure about the type of a value, the interpreter can tell you:
Figure 2.8. Type() function is a inbuilt function to determine the datatype of the values.
If you are using commas to separate groups of digits, just like in 1,000,000. This is not a valid integer in Python, however no error is generated.
Figure 2.9. This is not a valid integer in Python, however no error is generated.
1,000,000 is interpreted by Python as a comma-separated series of integers.
Formal and natural languages
Natural languages are the languages people speak, they may be languages as English,Spanish,German and so on.
Formal languages are languages designed by humans for particular reasons.
Mathematicians, for instance, use a formal language which is especially good at indicating relationships between numbers and symbols.
Chemists portray the chemical structure of the molecule using a formal language.
Similarly, Programming languages are formal languages created to express computations.
You can check a list of such progamming languages on Wikipedia : List of programming languages
The structure of statements in formal languages is governed by strict syntax rules.
In mathematics, the statement 3 + 3 = 6 is correct, but 3+ = 3$6 is not.
H2O is a syntactically correct formula in chemistry, but 2Zz is not.
Tokens are basic language elements such as words, numbers, and chemical elements.
Among the issues with '3+ = 3$6' is that '$' is not a legal mathematical symbol.
The 2nd kind of syntax rule governs how tokens are merged.
The equation 3 + /3 is illegal because, despite the fact that + and / are legal tokens.
Users must figure out all the structure of a sentence in English or a statement in a formal language when users read it , This is known as parsing.
Debugging
Figure 2.10. On September 9, 1947, Captain Grace M. Hopper removed the first computer bug, hence the term "Bugs".
Programmers make errors. For illustrative purposes, programming errors are referred to as bugs, and the method of hunting them down is referred to as debugging.
Learning to debug can be frustrating, but it is a valuable skill that is useful for many activities beyond programming.
Copyright © 2022-2023. Anoop Johny. All Rights Reserved.