Python ProgrammingFrom Basics to Advanced Concepts
A beginner-friendly Python course covering setup, syntax, data structures, control flow, functions, files, exceptions, generators, OOP and modern Python patterns.
Your Learning Progress
Module 1 – Python Basics
Understand what Python is, how to install and run it, and how to work with variables, data types, casting, comments and I/O.
1. Introduction to Python
Definition: Python is a high-level, interpreted programming language known for its clear syntax, readability, and wide use in web development, automation, data science, scripting, artificial intelligence, and general-purpose programming.
Why Python is popular
- Easy to read and write.
- Great for beginners.
- Large standard library.
- Huge ecosystem of third-party packages.
- Useful in many domains.
Example use cases
- Building websites
- Data analysis
- Automation scripts
- Machine learning
- File processing
2. Installing Python and Running Code
Python can be installed from the official Python website. Once installed, you can run code in the interactive shell,
1.pyRunning a script:
1python hello.pyExample file:
1print("Hello, World!")3. Hello World
1print("Hello, World!")Explanation
- displays output on the screen.code1print()
- The text inside quotes is a string.
- This is the simplest Python program.
4. Syntax and Indentation
Python uses indentation to define code blocks instead of braces.
1if 5 > 2:2 print("Five is greater than two")- The colon starts a block.code1:
- The indented line belongs to that block.
- Indentation is mandatory in Python.
- Do not mix tabs and spaces in the same block.
5. Variables
Definition: A variable is a named container used to store a value.
1age = 182name = "John"3print(name)- stores an integer.code1age
- stores a string.code1name
- Python does not require explicit type declarations.
Variable naming rules
| Valid | Invalid |
|---|---|
code | code |
code | code |
code | code |
code |
Use meaningful names, prefer lowercase with underscores, and avoid reserved words.
6. Basic Data Types
Python has several built-in types.
| Type | Meaning |
|---|---|
| str | text |
| int | integer |
| float | decimal number |
| complex | complex number |
| bool | true / false |
| list | ordered, mutable collection |
| tuple | ordered, immutable collection |
| set | unordered unique collection |
| dict | key-value mapping |
| range | numeric sequence |
7. Strings, Numbers, Booleans
1hello = "Hello World"2multi_string = """Multiline3Lorem ipsum dolor sit amet,4consectetur adipiscing elit"""5 6x = 1 # int7y = 2.8 # float8z = 1j # complex9 10my_bool = True11print(bool(0)) # False12print(bool(1)) # True8. Type Checking and Casting
1x = 12print(type(x)) # <class 'int'>3 4x = int("3")5y = float("4.2")6z = str(2)- Type checking helps you understand what kind of value a variable contains.
- Casting converts one data type into another.
9. Comments
1# This is a single-line comment2print("Hello World") # inline comment3 4"""5This is a multi-line comment6used for documentation.7"""10. Input and Output
1name = input("Enter your name: ")2print("Hello,", name)- waits for user input.code1input()
- The returned value is always a string.
11. Arithmetic Operations
1result = 10 + 30 # 402result = 40 - 10 # 303result = 50 * 5 # 2504result = 16 / 4 # 4.0 (floating-point division)5result = 16 // 4 # 4 (floor division)6result = 25 % 2 # 1 (remainder)7result = 5 ** 3 # 125 (exponent)Compound assignment:
1counter = 02counter += 103message = "Part 1."4message += "Part 2."12. Formatted Output
1name = "John"2age = 233 4# %-style5print("%s is %d years old." % (name, age))6 7# .format()8print("My name is {}, I'm {}".format(name, age))9 10# f-strings (preferred)11print(f"My name is {name}, I'm {age}")12num = 1013print(f"{num} + 10 = {num + 10}")Module Recap
- What Python is and why it is used.
- How to write and run a simple Python program.
- How indentation controls structure.
- How variables, data types and casting work.
- How to print output and accept input.
- How basic arithmetic and formatting work.
Practice Drill
Module 1 Quiz
Practice Drill Bank
Every practice drill from the course, organised by module. Rehearse these until they feel automatic.
Final Revision Checklist
Tick items as you master them — progress saves automatically.
Module 1 – Python Basics, Setup, Syntax, Variables & Data Types
Module 2 – Strings, Lists, Tuples, Sets & Dictionaries
Module 3 – Control Flow, Conditions & Loops
Module 4 – Functions, Modules & Advanced Concepts
Module 5 – File Handling, Exceptions & Generators
Module 6 – Classes, Objects, Inheritance & Advanced Python
Congratulations!
You've finished the CodeStudio Python Programming course. Revise, drill, and keep building.