Python Part2
Python Part2
P
9. WHICH ARE THE BASIC ASPECTS OF COMPUTER PROGRAM?
There are two basic aspects of computer programming ie; Data and Instructions.
*To work with data, it is important to understand variables and data types.
*To work with instructions, it is important to understand control structures and statements.
Example Data
type
X= ‘Hello World” str
X= 20 int
X=20.5 float
X=1j complex
X=[ “apple”,”banana”,”cherry”] list
X=(“apple”,”banana”,”cherry”) tuple
X=range(6) range
X={“name” : ” john” , ”age” :36} dict
X={“apple”,”banana”,”cherry”} set
Example:
if-else condition , case statements, for loops, and while loops are all control structures.
12. LIST AND DEFINE THE TYPES OF CONTROL STRUCTURES.
A) SEQUENTIAL
Sequential execution is when statements are executed one after another in order. You don't need to do
anything more for this to happen.
B) SELECTION
Selection used for decisions, branching - choosing between 2 or more alternative paths.
EXAMPLE : If, if...else and if-elif-else
If you have two or more courses of action to choose in your program, a perfect way to handle this is
through if-else conditionals.
C) REPETITION
Repetition used for looping, i.e. repeating a piece of code multiple times in a row.
while loop
for loop
A token is the smallest individual unit in a python program. All statements and instructions in a
program are built with tokens. The various tokens in python are :
1. Keywords:
*Keywords are words that have some special meaning or significance in a programming
language and they can’t be used as variable names. In Python we have 33 keywords some of
them are:
try, False, True, class, break, continue, and, as, assert, while, for, in, raise, except, or, not, if,
elif, print, import, etc.
2. Identifiers:
*Identifiers are the names given to any variable, function, class, list, methods, etc. for their
identification.
3. Literals or Values:
Literals are the fixed values or data items used in a source code. Python supports different
types of literals such as:
a) Arithmetic operators ( +, -, *, /, %)
b) Assignment operators(=, +=, -+, *+)
c) Comparison operators (==,!=, >, <, >=, <=)
d) Logical operators ( and , or, not)
e) Identity operators
f) Membership operators
g) Bitwise operators
5. Punctuators: These are the symbols that used in Python to organize the structures,
statements, and expressions. Some of the Punctuators are: [ ] { } ( ) @ -= += *= //= **== = ,
etc.
A library is a collection of pre-written code that you can use to perform specific tasks.
EXAMPLE :
Matplotlib: This library is responsible for plotting numerical data.
Pandas: Pandas are an important library for data scientists.
Numpy: The name “Numpy” stands for “Numerical Python”.
Scipy: solve scientific and mathematical problems
Modules are simply files with the “. Py” extension containing Python code that can be imported
inside another Python Program.
By using the command line ‘ import ‘ we can import secondary file module in the main module.