Your technical depth starts here.
Python Basics, Setup, Syntax, Variables & Data Types
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, .py script files, notebooks, or IDEs such as VS Code or PyCharm.
Running a script:
python hello.pyExample file:
print("Hello, World!")3. Hello World
print("Hello, World!")Explanation
print()displays output on the screen.- 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.
if 5 > 2:
print("Five is greater than two")- The colon
:starts a block. - 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.
age = 18
name = "John"
print(name)agestores an integer.namestores a string.- Python does not require explicit type declarations.
Variable naming rules
| Valid | Invalid |
|---|---|
age | 1age |
my_name | my-name |
total1 | class |
is_active |
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
hello = "Hello World"
multi_string = """Multiline
Lorem ipsum dolor sit amet,
consectetur adipiscing elit"""
x = 1 # int
y = 2.8 # float
z = 1j # complex
my_bool = True
print(bool(0)) # False
print(bool(1)) # True8. Type Checking and Casting
x = 1
print(type(x)) # <class 'int'>
x = int("3")
y = float("4.2")
z = str(2)- Type checking helps you understand what kind of value a variable contains.
- Casting converts one data type into another.
9. Comments
# This is a single-line comment
print("Hello World") # inline comment
"""
This is a multi-line comment
used for documentation.
"""10. Input and Output
name = input("Enter your name: ")
print("Hello,", name)input()waits for user input.- The returned value is always a string.
11. Arithmetic Operations
result = 10 + 30 # 40
result = 40 - 10 # 30
result = 50 * 5 # 250
result = 16 / 4 # 4.0 (floating-point division)
result = 16 // 4 # 4 (floor division)
result = 25 % 2 # 1 (remainder)
result = 5 ** 3 # 125 (exponent)Compound assignment:
counter = 0
counter += 10
message = "Part 1."
message += "Part 2."12. Formatted Output
name = "John"
age = 23
# %-style
print("%s is %d years old." % (name, age))
# .format()
print("My name is {}, I'm {}".format(name, age))
# f-strings (preferred)
print(f"My name is {name}, I'm {age}")
num = 10
print(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.
