Introduction
Basically, in every programming languages, there are components which act as a building blocks to build source code consisting line of codes. It is no different with python programming language. It is also consists of several components. Actually those components are in the following lists :
- Packages
This is a components which can be available at the top part of the source code. Actually, it is an instruction to be able to import something. It will instruct the interpreter of the python language to import the package name exist after the keyword import. The urge to import something is necessary in order to avoid reinventing the wheel. Instead of building some functions which already available from another packages, it will be more simple to import it. So, whenever there is a need in order to import a certain function available in a certain package, this component is a necessary. For an example, a simple package available such as math. The following is an example in a line of code :
import math
For an example, the following is the process for importing a package with the name of ‘math’ :
C:\Users\Personal>python Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import math >>> print("PI ",math.pi) PI 3.141592653589793 >>>
- Statements
The term statements in this context is a normal line of code. It is basically contain instruction for the interpreter of the python language. Actually, packages in the above component actually is a part of a statement. The statement is instructing the python language interpreter to import a package. So, what is another example below for showing a statement ?. The following is an actual statement executing a function with the name of ‘print’ to print a string and also a constant of pi from math package.
print("PI ",math.pi)
It will instruct the python language interpreter to print a string of ‘PI’ following with the value of the pi constant from math package as follows :
C:\Users\Personal>python Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import math >>> print("PI ",math.pi) PI 3.141592653589793 >>>
- Variables
It is an entity for storing and saving values. The values can be any form of types which is available in python programming language. The following is an example of defining a value in a variable :
>>> mypi = 3.2 >>> print("My PI",mypi) My PI 3.2 >>>
I define a variable with the name of mypi. So, for an example in the above case, instead of retrieving the value from a constant with the name of pi from math package, just define a variable. A certain value will be available for further assignment to the variable. The value for that variable is ‘3.2’ which is a float number. Soon after, printing the variable will actually display the value of it which is 3.2
- Literals
Literals are the one available as the content for variable. It is available in symbols ranging from numbers, characters or strings. In the above context, the example is 3.2 for the float data type. Another example exist as follows :
>>> greetings = "Hello World !" >>> print(greetings) Hello World ! >>>
The literals are “Hello World !”. It is a string data type where the assignment is into a variable with the name of ‘greetings’.
- Operators
In case of the operators, those are actually symbols. It is different with literals because these symbols is available to manipulate and to modify the value of variables. So, using these operators, the value or the literals within variables will change and accepting modification. One of the operator’s example is the plus sign (+). The following is an example of the plus sign operator’s usage :
C:\>python Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> a = 5 >>> b = 8 >>> c = a + b >>> print("The value of a + b is ",c) The value of a + b is 13 >>> a = 'Hello ' >>> b = 'World !' >>> print(a + b) Hello World ! >>>
One thought on “Python Programming Language Source Code Components”