Back to Premium Vault
Premium Vault / Python ProgrammingFree Programming Course

CODESTUDIO / GO BEYOND SYNTAX

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.

6 learning modules18 review questions32 practice drillsSelf-paced learning
Python Programming / learning workspace

Your technical depth starts here.

MODULE 1 / 6

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:

bash
python hello.py

Example file:

python
print("Hello, World!")

3. Hello World

python
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.

python
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.

python
age = 18
name = "John"
print(name)
  • age stores an integer.
  • name stores a string.
  • Python does not require explicit type declarations.

Variable naming rules

ValidInvalid
age1age
my_namemy-name
total1class
is_active

Use meaningful names, prefer lowercase with underscores, and avoid reserved words.


6. Basic Data Types

Python has several built-in types.

TypeMeaning
strtext
intinteger
floatdecimal number
complexcomplex number
booltrue / false
listordered, mutable collection
tupleordered, immutable collection
setunordered unique collection
dictkey-value mapping
rangenumeric sequence

7. Strings, Numbers, Booleans

python
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))  # True

8. Type Checking and Casting

python
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

python
# This is a single-line comment
print("Hello World")  # inline comment

"""
This is a multi-line comment
used for documentation.
"""

10. Input and Output

python
name = input("Enter your name: ")
print("Hello,", name)
  • input() waits for user input.
  • The returned value is always a string.

11. Arithmetic Operations

python
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:

python
counter = 0
counter += 10
message = "Part 1."
message += "Part 2."

12. Formatted Output

python
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.