0 ratings 0% found this document useful (0 votes) 4 views 15 pages Python Fundamentals For Computer Science
This document is a comprehensive guide to Python programming, covering its foundational concepts, syntax, and flow control. It includes details on data types, operators, control structures, and error handling, aimed at helping students understand and apply Python effectively. The syllabus roadmap outlines practical work and assessments for mastering Python programming skills.
AI-enhanced title and description
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here .
Available Formats
Download as PDF or read online on Scribd
Go to previous items Go to next items
Save Python_Fundamentals_For_Computer_Science For Later
CLASS 11 COMPUTER SCIENCE (CODE 083)
ras
ee
et ey Cc
Getting Started with Python
A Comprehensive Guide: From Basic Syntax to Flow Control
Unit 2; Computational Thinking and Programming - 1The Foundation:
Understanding Python
Python is a high-level, interpreted, free,
and open-source programming language
invented by Guido van Rossum. It is
case-sensitive and platform-
independent.
“Computer programming is an art...
because it applies accumulated knowledge
to the world, because it requires skill and
ingenuity, and especially because it
produces objects of beauty.” - Donald
Knuth
Source Code
v
Interpreter
Processes statements one by
‘one, Stops immediately on
ror.
v
Machine Language
Binary (0s and 13) execution.The Workshop: Modes of Execution
Interactive Mode | Script Mode
Instant execution. Data lost onexit. 1 — Save as.-py files. Run full modules.
Best for testing. i Best for building.
“see ~)
eS oe 1 (1a [Link]-Crncepes-1py (270
3 print("Save Earth")
>>> 4-2 print("Preserve Future")
2 1
>>> "Hello" + "World" H
‘HelloWorld' 1
>>> ‘
\ pI )Engineering Manual
The Grammar: Keywords, Identifiers & Comments
1. Keywords (Reserved Words)
‘Words with special meaning to the interpreter. Cannot be used as variable names.
False class finally is retum None continue for = lambda try True
def from nonlocal and, del global not with as elif
it or yield assert’ ~—else_— import «= pass. break except. in raise
2. Identifiers (Names)
Names for variables, functions, or objects.
‘© Must start with a letter (A-Z) or underscore (_).
Can contain letters, digits, and underscores.
* Case sensitive (Var != var)
* No special symbols (@, $, %).
3. Comments (Documentation)
Non-executable notes. Ignored by the interpreter.
# This is 9 conment
X= 5 # Assigns 5 to xThe Containers: Variables & Objects
In Python, everything is an Object.
Object Properties:
1, Identity (Address): id (object)
2. Type (Data Class): type(object)
3. Value (Data Content)
Variables:
Named references to objects. Created upon
assignment.
LValue (Variable) = R-Value (Object/Expression)
Object Reference
JetBrains Mono
[— Name (Identifier)
Reference
20
The Object
num1
(The Identifier)
Object in MemoryRaw Materials I: Numeric & Boolean Data Types
Type Description
Integer (int) Whole numbers, positive or negative.
Floating Point (float) | Numbers with decimal points or
scientific notation.
Complex (complex) Real and Imaginary parts (A + Bj).
Boolean (bool) Subtype of integer. Truth values.
None (NoneType) Represents the absence of a value.
Booleans: True is non-zero/non-null. False is 0.
Examples
-2 @ 125
-2.04 4.8 -9,8*10%2
See pony
True (1), False (0)
NoneRaw Materials Il: Sequence Data Types
Ordered collections indexed by integers.
“© String (str)
Sequence of characters.
Immutable.
Hle[ala o|
[ ] List Qist)
Ordered collection
Mutable (Changeable).
list! = [5, 3.4, "Delhi"]
( ) Tuple (tuple)
Ordered collection
Immutable (Fixed).
tup = (10, 20, "Apple")
Omma aeeo ain omaaer a
usti>] 5 [3.4] "Delhi"Raw Materials Ill: Sets & Dictionaries
Sets (‘set*) Dictionaries (“dict*)
Keys Values
10
20 20 ‘Fruit’ ‘Apple’
3.14 ‘Price’ 120
+ Unordered collection in {}’. * Key-Value pairs in {}’. Mapping
* No duplicates allowed. « Accessed via Keys, not index.
5 d= {'Fruit': ‘Apple’, ‘Price’: 120}
Peete ee print(d['Price']) # Output: 120The Physics: Mutable vs. Immutable
The Classification
+ Immutable (Cannot change in place): + Mutable (Changeable in place):
o int o° list
° float ° dict
° bool ° set
o str
© tuple
Memory Visualization
Before and After After (num1 = num2 + 100)
num
id: 2200
300
id: 1000 num id: 1000
Immutable types create new objects when modified.The Tools I: Arithmetic & Relational Operators
Arithmetic Operators
Relational Operators
+ (Add) | (Sub) | «(mun | 7 (0m Return Boolean True or False.
+ == (Equal)
. + 15 (Not Equal)
// Floor Div: 13 // 4 -> *3* ne
- <
1 cs
% Modulus: 13 % 5° -> “3°
Example: strl > str2°
x Exponent: 2 ** 3° -> “8° (Lexicographical check)The Tools II: Logical & Assignment Operators
Logical Operators (Roboto)
Clean truth table.
A BA and BJA or B| not A
True | True | True | True | False
True | False | False | True | False
False | True | False | True | True
False | False | False | False | True
and: True only if BOTH are True.
or: True if ONE is True.
not: Inverses the boolean value.
Assignment Operators (Ro!
Update values efficiently.
= : Assigns value
+= : Add and assign
boto)
JetBrains Mono
JetBrains Mono
-= :Subtract and assign JetBrains Mono
*= ;Multiply and assign JetBrains Mono
/= :Divideandassign JetBrains Mono
x t= 5-—> x] = [x] + [5
String Special Case:
+ =Concatenation ("Hello" + "World")
* = Repetition ("India" * 2)The Pathways: Flow of Control (Selection)
The Structure: if - elif - else
if num > 0:
print('Positive')
elif num < 0: Indentation
print('Negative') Block
else:
print(‘Zero')
Print Positive
Print Negative
Print ZeroThe Engines: Flow of Control (Repetition)
The For Loop
Iterate over a sequence (range, list,
string).
for i in range(1, 5, 2):
1 Zee hay oe 6
S excluded
The While Loop
Execute while condition
is True,
while x > 0:
Watch out for
Infinite Loops.
Jump Statements
—> break : Exit loop.
for i in range(5):
bi + break
print (i)
# Output: 8, 1, 2
— continue : Skip to next
iteration.
for i in range(s):
if i == 2: continue
print (i)
# Output: 8, 1, 3, 4Troubleshooting: Errors & Debugging
ql
Syntax Errors
Grammar rules violated.
Detected BEFORE
execution.
Missing colon (:)
S
Runtime Errors
Abnormal Termination.
Occurs DURING execution.
Division by Zero
NameError
i
Logical Errors
Incorrect Output.
Code runs, but logic is
wrong. Hardest to detect.
Wrong formula used.Syllabus Roadmap: Unit 2
Computational Thinking & Programming (45 Marks)
Practical Work (30 Marks) Success Checklist
Fe 1. Lab Test (8 Marks) ¢ Master Syntax & Indentation.
Python programs, + Deeply understand Data
rf 2. Report File (7 Marks) Types.
Min 20 programs. * Practice Loops daily.
3. Project Work (8 Marks) e Trace code manually to fix
Real life application. Logical Errors.
1) 4. Viva Voce (7 Marks)
Start Coding Now.