Programming Fundamentals of Python - Summary

Coding Rules

  • Proper indentation is crucial; use four spaces.

  • Implicit continuation allows statement breaks after parentheses/ brackets and operators.

  • Explicit continuation uses \ for statement breaks anywhere.

Comments

  • Use comments to clarify complex code, but avoid excessive commenting.

  • Update comments when code changes.

Data Types

  • Common types:

    • str: Strings (e.g., "Mike")

    • int: Integers (e.g., 21)

    • float: Floating-point (e.g., 21.9)

Identifier Naming Rules

  • Start with a letter or underscore.

  • Use no spaces or special characters (except underscore).

  • Don't start with a number or use reserved keywords.

Python Keywords

  • Examples: and, as, break, class, def, if, not, while, etc.

Naming Conventions

  • Start variable names with lowercase; use underscore notation or camel case for readability.

  • Avoid using built-in function names.

Arithmetic Operators

  • +: Addition; -: Subtraction; *: Multiplication; /: Division; //: Integer Division; %: Modulo; **: Exponentiation.

Order of Precedence

  • Highest to lowest: **, * / // %, + -.

String Operations

  • Concatenate with + or use f-strings for better readability.

Input Function

  • input([prompt]) collects user input as a string.

Number Functions

  • Use int(), float(), round() to handle numeric data.

Types of Errors

  • Syntax errors: violate Python rules; caught before execution.

  • Runtime errors: exceptions during execution.

  • Logic errors: incorrect results without errors.

Debugging

  • Use breakpoints to pause execution for debugging.

  • IDLE Debug Control allows step-into, step-over, and step-out functionality for inspection during execution.