Operators & Expressions

ECON 3209 · Week 1, Lecture 3 · Kerala Agricultural University

Department of Development Economics, KAU

Autumn 2026

Learning Outcomes

By the end of this lecture, you will be able to:

  1. Use all Python arithmetic, comparison, logical, and assignment operators
  2. Build compound boolean expressions to filter data
  3. Understand operator precedence and use parentheses correctly
  4. Apply string and membership operators
  5. Write clean, readable expressions for economic computations

Arithmetic Operators — Review

/ always returns a float in Python 3. Use // when you need whole-number division (e.g., counting periods).

Economic Calculations

Comparison Operators

Logical Operators

Short-Circuit Evaluation

Short-circuit evaluation is how Python avoids runtime errors in compound conditions.

Assignment Operators

Membership Operators

Identity Operators

Operator Precedence

Rule of thumb: If you’re unsure about precedence, add parentheses. They’re free and make code readable.

String Operators

Building Compound Expressions

None — The Null Value

🏋️ Exercise

A cooperative bank has the following loan eligibility rules:

  • Minimum monthly income: ₹20,000
  • Maximum loan amount: 20× monthly income
  • Minimum credit score: 650
  • No existing defaults (has_default = False)

Write a Python expression that evaluates to True if an applicant with income=35000, loan=500000, credit_score=680, has_default=False is eligible. Use meaningful variable names and print the individual checks.

Summary

Key Takeaways — Lecture 3

Arithmetic: + - * / // % ** — watch out for / vs //

Comparison: == != > >= < <= — return bool; can be chained

Logical: and or not — use for compound conditions; short-circuit evaluation saves errors

Assignment: += -= *= /= — compact in-place updates

Membership: in / not in — works on lists, strings, dict keys

Precedence: ** > * / > + - > comparisons > not > and > or — use () when unsure

None represents missing/absent values — check with is None

Week 1 Complete!

Week 1 Summary

This week you built the foundation of Python programming:

Lecture Topic Status
1 Getting Started — Jupyter, arithmetic, imports
2 Variables & Data Types — int, float, str, list, dict
3 Operators & Expressions — arithmetic, boolean, compound

Next Week: Control Flow & Functions — if/else, for loops, while loops, defining your own functions