Python Notes Unit-4
Python Notes Unit-4
Algorithm-
A logical step-by-step method to solve the identified problem is called algorithm.
Flowchart-
A flowchart is the graphical or pictorial representation of an algorithm with the help of different
symbols.
Flowchart symbols-
Program-
A computer program is a collection of instructions that perform a specific task when executed by
a computer.
A programming language is a vocabulary and set of grammatical rules for instructing a computer
to perform specific tasks. Example- BASIC, Pascal, C, Java, Python, etc.
What is Python?
Interactive mode is convenient for beginners It requires to save our code so that we may
as it gives instant result. modify and reuse the code.
Python Statements-
Instructions written in the source code for execution are called statements. There are different
two of statements-
1. Single Line statements – eg n=50
2. Multi Line statements - Statements in Python can be extended to one or more lines using
parentheses (), braces {}, square brackets [], semi-colon (;), continuation character slash (\).
Python Comments -
A comment is text that doesn't affect the outcome of a code, it is just a piece of text to
provide some information. They are of two types-
Keywords are the reserved words in Python used by Python interpreter to recognize the
structure of the program.
Identifiers-
Variable-
A variable is a named location used to store data in the memory. It is helpful to think of variables
as a container that holds data which can be changed later throughout programming. For example
x=42, y=2
Constant-
A constant is a type of variable whose value cannot be changed.
1) Python Numbers - Number data type stores Numerical Values. These are of two types:
a) Integer & Long - Integers are the whole numbers consisting of + or – sign with decimal digits
like 100000, -99
b) Float / floating point - Numbers with fractions or decimal point are called floating point
numbers such as 0.0, -21.9
List Tuple
They are mutuable. They are immutable.
Enclosed in square brackets []. Enclosed in parenthesis ().
Length can be changed, i.e., a new element Length is fixed, i.e., new elements can’t be
can be added. added.
Employee = [‘A’, ‘B’, ‘C’] Employee = (1001, 1002, 1003)
3) Sets - Set is an unordered collection of values, of any data type, with no duplicate entry.
Example:
>>> a = {1,2,2,3,3,3}
>>> a
{1,2,3}
4) Mapping - This data type is unordered. Dictionaries fall under Mappings.
Dictionaries- Dictionary is an unordered collection of key-value pairs. They are defined within
braces {} with each item being a pair in the form key: value.
Example
d = {1:'Ajay','key':2}
print() function -
print() function is used to display or show the output. It is an inbuilt function of python library.
Ex. A=10
a = "Hello World!"
print(a)
input() function-
The input() function is used to take user’s input in the program.
Python Operators -
Operators are special symbols which represent computation. They are classified in four
categories: -
Type Conversion -
The process of converting the value of one data type (integer, string, float, etc.) to another data
type is called type conversion. Python has two types of type conversion.
1. Implicit Type Conversion - Implicit Type Conversion In Implicit type conversion, Python
automatically converts one data type to another data type. This process doesn't need any user
involvement.
Example:
A=12
B=34.5
print(A+B)
2. Explicit Type Conversion - In Explicit Type Conversion, users convert the data type of an object
to required data type. We use the predefined functions like int(), float(), str(), etc to perform
explicit type conversion. It is also called typecasting.
x = 20.3
y = 10
print(int(x) + y)