Python Programming Course Overview
Python Programming Course Overview
Course Outcomes :
• Syllabus
Features of Python:
• Easy to Learn
• Easy to Read and Maintain
• Interactive (shell mode)
• Object Oriented
• Interpreted
• Platform Independence / Cross-platform Compatibility
• Open Source
• Scalable
Program Name: Python Programming Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Faster
5
Program Name: Python Programming Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
IDE
IDE is short for Interactive Development Environment.
• Code Editor: A text editor with features like syntax highlighting,
auto-completion, and code formatting to write and edit code
efficiently.
• Debugger: Tools for debugging code, allowing you to set
breakpoints, step through code, inspect variables, and analyze the
execution flow.
• Compiler/Interpreter Integration: Built-in support for compiling or
interpreting code, often with one-click build and run capabilities.
7
Program Name: Python Programming Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
IDE (cont…)
IDE is short for Interactive Development Environment.
• Project Management: Features for organizing and managing
project files, directories, and dependencies.
• Plugins and Extensions: Support for adding additional
functionality through plugins or extensions, customizing the
IDE to fit specific needs or preferences. E.g. Prettier, Live
Server, Code Runner, Bracket Pair Colorizer
8
Program Name: Python Programming Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Review Questions
• Which version of Python is currently up to date?
– Python1
– Python2
– Python4
– Python3
• Which of the following is not a characteristic of Python?
– Object Oriented
– Interpreted
– Requires manual memory management
– Platform Independence
9
Program Name: Python Programming 9 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Review Questions
• In a Python context, the acronym IDE stands for:
– Integrated Development Environment
– Interpretive Dance Lessons
– Interstellar Dust Laser Explorer
– None of the above
Review Questions
11
Program Name: Python Programming 11 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Session Plan
12
Program Name: Python Programming 12 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Python Identifiers
Names used to identify various elements in code such as variables, functions,
classes, modules, and other objects.
These elements are:
– Variables
– Functions
– Lists
– Tuples
– Dictionary
– Class
– Object
13
Program Name: Python Programming 13 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Python Identifiers
Rules for identifier name –
It can be a combination of A-Z, a-z, 0-9, or underscore.
It can’t start with digit.
It should start with an alphabet character or an underscore ( _ ).
It should not contain special characters except underscore.
It should not contain white space.
It cannot be a reserved python keyword.
14
Program Name: Python Programming 14 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Python keywords
Python keywords are special reserved words that have specific meanings and
purposes.
function name
variable name
identifiers
15
Program Name: Python Programming 15 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Contd..
The list of such keywords is mentioned below –
True False class def except
if elif else try is
raise finally for in lambda
not from import global continue
nonlocal pass while break del
and with as yield async
or assert None return await
16
Program Name: Python Programming 16 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
18
Program Name: Python Programming 18 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
19
Program Name: Python Programming 19 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Numeric Literals
Numeric literals are of multiple types based on the number type. The types of
numeric literals are integer, float (decimal numbers), and complex numbers.
Float Literals - These are basically real numbers that consist of both integer as well
as fractional parts.
-12.45, 12.90, 100.0
Example -
20
Program Name: Python Programming 20 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Numeric Literals
Complex Number Literals - The numerals will be in the form of a + bj, where ‘a‘ is
the real part and ‘b‘ is the complex part.
Example -
10j , 1 + 0j , 10 + 2j, 12 – 5j
21
Program Name: Python Programming 21 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
String literals
When set of character are enclosed in quotes ( single quotes or double quotes) then it formed
a string literals. 'glbitm' 'rate_of_interest' '123', '12.5'
Example -
“GLBITM" "Simple_interest" "A1" "456 "
Example -
22
Program Name: Python Programming 22 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Example -
True, False
In Python, True represents the Non-zero value and False represents the value as
Zero.
23
Program Name: Python Programming 23 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Tuple: A tuple is a set of values of different types. The values are separated by
comma(,) and enclosed within parentheses “ ( ) “. It is immutable.
Example -
( 1, 23, 23.4, 100 )
Example –
{ 'name':'BOB', 'age':24, 'marks':59.4 }
Set literals: Set is a collection of values of different types. The values are separated
by comma (,) and enclosed within curly-braces “{ }”. It is unordered and contains
only unique value.
{ 1, 23, 45, 56, 67 }
Example -
{ 'Ram', 'Rajesh', 12, 34.5 }
25
Program Name: Python Programming 25 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Variables
Variable are the names given by the users to the memory locations to store the
data values.
In Python, variable need not to be declared or defined in advances, as we do in
many other programming language.
Variables
Valid Variable Names:
• Name
• Num1
• Rate_of_interest
• abc
• Marks1
1) age
2) _age
3) -age
4) age_*
5) Item-Number-1 28
Program Name: Python Programming 28 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
type() command
type () command helps in finding the type of the specific declared variable or a
value.
Example –
31
Program Name: Python Programming 31 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
id() command
id () command gives the unique id for a given objects / variable / values.
Note - The unique id is the memory address and will be different each time when
you run for variable or values.
Example –
Unique Identity
32
Program Name: Python Programming 32 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
dir() command
dir () command is a vital function that returns all the properties and methods
associated with given objects.
Example –
33
Program Name: Python Programming 33 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
34
Program Name: Python Programming 34 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Type conversion
The process of converting the value of one data type (e.g. integer, string, float, etc.)
to another data type is called type conversion.
Example -
12.5 12 ( float to integer )
'123' 123 ( string to integer )
12 12.0 ( integer to float )
Example –
Note - Python promotes the conversion of the lower data type (integer) to the
higher data type (float) to avoid data loss.
36
Program Name: Python Programming 36 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Example –
38
Program Name: Python Programming 38 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Example –
Example –
40
Program Name: Python Programming 40 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
42
Program Name: Python Programming 42 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
43
Program Name: Python Programming 43 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
44
Program Name: Python Programming 44 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Operators
Operators are symbol, used to perform mathematical and logical
operation.
45
Program Name: Python Programming 45 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Arithmetic operators
There are seven arithmetic operators, and these are of:
Operator Meaning Example
Add two operands or x+y
+ unary plus +2
Subtract right operand from the left or x-y
- unary minus -2
* Multiply two operands x*y
Divide left operand by the right one (always results into
/ float) x/y
Modulus - remainder of the division of left operand by the
% right
x % y (remainder of x/y)
Floor division - division that results into whole number
// adjusted to the left in the number line x // y
** Exponent - left operand raised to the power of right x**y (x to the power y)
46
Program Name: Python Programming 46 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Arithmetic operators
Example of all mentioned arithmetic operators
47
Program Name: Python Programming 47 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
48
Program Name: Python Programming 48 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Note - The == and != operators can actually work with values of any data
type. 50
Program Name: Python Programming 50 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Bitwise Operators
Bitwise operators act on the bits and performs bit by bit operation on the
operands.
Operator Meaning
Example – Evaluate 2 & 7 & Bitwise AND
| Bitwise OR
How it works - ~ Bitwise NOT
Step 1 – Convert 2 in binary 0010 ^ Bitwise XOR
Step 2 – Convert 7 in binary 0111
>> Bitwise right shift
Step 3 – Perform Bitwise & operation
Step 4 – Convert the result back to decimal << Bitwise left shift
51
Program Name: Python Programming 51 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
0 0 0 0 0
A ~A
0 1 0 1 1 0 1
1 0
1 0 0 1 1
1 1 1 1 0
52
Program Name: Python Programming 52 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Explanation –
Explanation –
Explanation –
Explanation –
56
Program Name: Python Programming 56 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Explanation –
Step 1 – Convert 9 in binary 1001 Step 3 – Convert the result (100) back
Step 2 – Shift 1001 towards right by one to decimal 4
position.
1001
100
10 01
1 will discarded
57
Program Name: Python Programming 57 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Assignment operators
Operator Example Equivalent to
= x=5 x=5
Logical Operators
Logical operators perform Logical AND, Logical OR and Logical NOT operations.
Operator Meaning Example
and True if both the operands are true x and y
or True if either of the operands is true x or y
not True if operand is false (complements the operand) not x
x y x and y x or y
Truth Table – x not x
T T T T
T F
T F F T F T
F T F T
F F F F
59
Program Name: Python Programming 59 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Logical Operators
Example –
60
Program Name: Python Programming 60 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Identity Operators
Identity Operators – is and is not are the identity operators in Python.
They are used to check if two values (or variables) are located on the same part of the
memory or not.
Operator Meaning
is Gives True if the operands are identical (refer to the same ID or Memory)
is not Gives True if the operands are not identical (do not refer to the ID or Memory)
Example
61
Program Name: Python Programming 61 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Membership Operators
in and not in are the membership operators in Python.
They are used to test whether a value or variable is found in a sequence (string, list,
tuple, set and dictionary) or not.
Operator Meaning
in Gives True if value/variable is found in the sequence otherwise False
not in Gives True if value/variable is not found in the sequence otherwise True
Example
62
Program Name: Python Programming 62 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
Operator Associativity: If an expression has two or more operators with the same
precedence, then Operator Associativity is used to find. It can either be Left to
Right or from Right to Left.
63
Program Name: Python Programming 63 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
64
Program Name: Python Programming 64 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
65
Program Name: Python Programming 65 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
66
Program Name: Python Programming 66 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
67
Program Name: Python Programming 67 Program Code: BCC302
Department of Information Technology.
Course Code: BCC 302 Course Name: Python Programming
68
Program Name: Python Programming 68 Program Code: BCC302