Python Programming Basics — Complete
Foundation Notes
These notes cover
every small building block
of Python you must understand
before jumping into lists,
OOP, tuples, sets, or dictionaries. No fluff. Straight facts. This is your mental map of Python.
1. What Programming Actually Is
Programming giving
= precise instructions to a computer
so it can: input
- take
process
- it using logic -
give output
Python is just a language we use to talk to the computer.
2. Python Program Structure
2.1 Statements
A statement is one complete instruction.
print("Hello")
- Python runs top to bottom, line by line.
3. Characters & Symbols (VERY IMPORTANT)
3.1 Comma ,
• Separates multiple values
print("A", "B", "C")
• Used in function arguments, lists, tuples
3.2 Dot .
• Accesses methods or properties of something
1
[Link]()
Means: use the upper ability of text
3.3 Colon :
• Starts a block of code
if x > 5:
Used in:
• if / elif / else
• loops
• functions
• classes
3.4 Semicolon ;
• Ends a statement (optional in Python)
a = 5; b = 6
❌ Not recommended. Python prefers clean lines.
3.5 Quotes ' ' and " "
• Used for strings (text)
"hello" 'hello'
Both are same. Triple quotes are for multi-line text.
4. Spaces & Indentation (CRITICAL)
Python uses indentation instead of brackets.
2
if x > 0:
print("Positive")
- 4 spaces = standard - Wrong spacing = program crash
Indentation shows ownership of code.
5. Comments
5.1 Single-line comment
# This is a comment
Used to: - explain logic - disable code
5.2 Multi-line comment
"""
This is a block comment
"""
6. Variables (Data Storage)
6.1 What is a variable?
A variable is a label pointing to data.
age = 18
- = is assignment, not math
6.2 Naming Rules
✔ letters, numbers, underscore ✔ cannot start with number ❌ no spaces
3
my_age = 20
7. Data Types (Core)
Type Purpose Example
int Whole numbers 5
float Decimal numbers 3.14
str Text "Hi"
bool True/False True
None No value None
Data type defines what you can do with data.
8. Input & Output
8.1 Output — print()
print("Hello")
- Displays data - Converts everything to text
8.2 Input — input()
name = input("Enter name: ")
- Always returns string
To convert:
age = int(input("Age: "))
4
9. Type Conversion (Casting)
int("5")
float("3.2")
str(10)
bool(1)
Used when Python guesses wrong type.
10. Operators
10.1 Arithmetic Operators
Operator Meaning
+ add
- subtract
* multiply
/ divide
// floor division
% remainder
** power
10.2 Comparison Operators
Operator Meaning
== equal
!= not equal
>< greater / smaller
>= <= greater/less equal
Returns True or False.
5
10.3 Logical Operators
Operator Meaning
and both true
or one true
not reverse
11. Conditional Statements
11.1 if
if x > 0:
print("Positive")
11.2 elif
elif x == 0:
11.3 else
else:
Python checks top to bottom, first match runs.
12. Brackets & Parentheses
12.1 Parentheses ( )
• Function calls
• Control precedence
print((2+3)*4)
12.2 Square Brackets [ ]
• Used for lists (later)
6
12.3 Curly Braces { }
• Used for dictionaries, sets (later)
13. Keywords (Reserved Words)
Words Python owns:
if, else, elif, True, False, None, and, or, not, for, while, break, continue,
pass, def, return, class
❌ Cannot be variable names.
14. Errors (Read This Carefully)
14.1 Syntax Error
• Wrong grammar
14.2 Runtime Error
• Program crashes while running
14.3 Logical Error
• Code runs, output wrong (most dangerous)
15. Functions (Basic Idea)
def greet():
print("Hello")
- Avoid repetition - Organize logic
16. Execution Flow
1. Read line
7
2. Execute
3. Move to next line
Functions only run when called.
17. Why These Basics Matter
If you don't master: - spacing - operators - conditions - input/output
Then: ❌ lists confuse you ❌ OOP feels impossible ❌ bugs eat your time
NEXT STEP
After this foundation, we topic
will go
by topic
: 1. Strings (deep) 2. Lists 3. Tuples 4. Sets 5.
Dictionaries 6. Functions (advanced) 7. OOP
Say "Start Strings" and we go hard.