0% found this document useful (0 votes)
5 views

Python Part2

Python important notes

Uploaded by

ayeshaalizeh173
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Python Part2

Python important notes

Uploaded by

ayeshaalizeh173
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

PYTHON 20SC02

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.

10. WHAT IS THE MEANING OF DATA TYPES OF PYTHON.

 Data type represents the type of data present inside a variable.


 In python it is not required to specify the type of data separately, based on value
provided the type will be assigned automatically.

Text Type: str

Numeric Types: int, float, complex

Sequence Types: list, tuple, range

Mapping Type: dict

Set Types: set, frozen set

Boolean Type: bool

Binary Types: bytes, byte array, memory


view

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

HGR, BPS. Page 1


PYTHON 20SC02
P
11. DEFINE PYTHON CONTROL STRUCTURES.
Control structures allow you to make decisions or control the order of execution of your
program.
It is basically decision-making process and decides how a computer program will respond when
given certain conditions and parameters.

Example:
if-else condition , case statements, for loops, and while loops are all control structures.
12. LIST AND DEFINE THE TYPES OF CONTROL STRUCTURES.

The three basic types of control structures:

1. Sequential 2. Selection (if, if-else, if-elif-else) 3. Repetation ( for & while


loop)

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

HGR, BPS. Page 2


PYTHON 20SC02
P

 for loop

13. WHAT ARE TOKENS IN PYTHON?

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:

(i) String Literals: “Computer Science”, ‘sam’, etc.


(ii) Character Literals: The character is enclosed in single or double-quotes.
(iii) Numeric Literals: These are the literals written in form of numbers. Python supports the
following numerical literals:
 Integer Literal , Float Literal , Complex Literal
(iv) Boolean Literals: Boolean literals have only two values in Python. These are True and False.
(v) Special Literals: Python has a special literal ‘None’. It is used to denote nothing, no values,
or the absence of value.
(vi) Literals Collections: Literals collections in python includes list, tuple, dictionary, and sets.
 List, Tuple , Dictionary, Set

HGR, BPS. Page 3


PYTHON 20SC02
P

4. Operators: Operators are used to perform operations on variables and values.

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.

14. WHAT IS LIBRARIES IN PYTHON?

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

15. WHAT IS THE PURPOSE OF LIBRARIES?


 Libraries are often used to reduce the amount of code a programmer needs to write by providing
reusable CODING.
 The total numbers of libraries in Python are more than 137000.
 All these libraries are used in machine learning, data science, data manipulation and
visualization, and more.

16. WHAT ARE MODULES?

Modules are simply files with the “. Py” extension containing Python code that can be imported
inside another Python Program.

17. how to import one python module in another python module?

By using the command line ‘ import ‘ we can import secondary file module in the main module.

HGR, BPS. Page 4

You might also like