0% found this document useful (0 votes)
2 views9 pages

Python Notes Unit-4

This document provides an introduction to Python programming, covering algorithms, flowcharts, and the Python programming language itself. It discusses features of Python, its integrated development environment (IDLE), data types, variables, constants, and operators, as well as functions like print() and input(). Additionally, it explains type conversion and the rules for naming identifiers and variables.

Uploaded by

bjpsharm986
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views9 pages

Python Notes Unit-4

This document provides an introduction to Python programming, covering algorithms, flowcharts, and the Python programming language itself. It discusses features of Python, its integrated development environment (IDLE), data types, variables, constants, and operators, as well as functions like print() and input(). Additionally, it explains type conversion and the rules for naming identifiers and variables.

Uploaded by

bjpsharm986
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Class IX/ Unit-4 (Introduction to Python) Notes

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?

• Python is a programming language created by Guido Van Rossum in 1991.


• It got its name from a BBC comedy series named as – “Monty Python’s Flying Circus”
Features of Python-
Applications of Python -

Integrated Development & Learning Environment (IDLE) –


IDLE is the standard, most popular Python development environment. It lets us edit, run, browse
and debug Python Programs from a single interface.
Python shell can be used in two ways: -
1. Interactive mode
2. Script mode

Interactive mode Script mode


This mode allows us to interact with OS. Script mode lets us create and edit Python
source file.
This mode is used for short scripts. This mode is used for long scripts.

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-

Single Line comment


A # sign is used to write a single line comment in the python program. For example,
#A statement to add two numbers
Multiline comments
The multiline comments are written in python using triple quotes. For example,
'''Write a python program to display the difference between two numbers, the first number
should be larger than second number'''
Keywords

Keywords are the reserved words in Python used by Python interpreter to recognize the
structure of the program.

Identifiers-

An identifier is a name given to entities like class, functions, variables etc.


Rules to name an Identifier-

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.

Rules and Naming convention for variables and constants-


Datatypes -
Every value in Python has a datatype which describes the type of data a variable holds. There are
various datatypes in Python-

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

2) Sequence- A sequence is an ordered collection of items, indexed by positive integers. Three


types of sequence data type available in Python are:
a) Strings- String is an ordered sequence of letters/characters. They are enclosed in single quotes
(‘ ‘) or double (“ “).
b) Lists
c) Tuple

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: -

1. Python Arithmetic Operators


Arithmetic operators are used with numeric values to perform common mathematical
operations:
2. Python Assignment Operators
Assignment operators are used to assign values to variables.

3. Python Comparison Operators


Comparison operators are used to compare values. It either returns True or False according to
the condition.
4. Python Logical Operators
Logical operators are used to combine conditional statements.

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)

You might also like