🐍

Python Basics Overview

Jul 2, 2025

Overview

This lecture covered the foundational concepts of Python programming, focusing on character sets, tokens, variables, assignments, operators, input/output functions, and the structure of a Python program.

Introduction to Python Fundamentals

  • Python is a high-level programming language with simple syntax and dynamic typing.
  • Basics include interactive/script modes, character sets, tokens, and program structure.

Character Sets in Python

  • The character set includes all valid characters Python can recognize (letters, digits, special symbols, spaces).
  • Supports ASCII and Unicode characters (A-Z, a-z, 0-9, special symbols, white spaces).

Tokens in Python

  • Tokens are the smallest units in a Python program, essential for syntax and structure.
  • Five types of tokens: keywords, identifiers, literals, operators, punctuators.

Keywords

  • Keywords are reserved words with special, predefined meanings (e.g., if, else, for, while, True, False, None).
  • Cannot be used as identifiers (variable or function names).

Identifiers

  • Identifiers are names given to variables, functions, classes, etc.
  • Must start with a letter or underscore, can contain letters, digits, underscores, and cannot use special symbols or keywords.

Literals

  • Literals are fixed values used directly in code (e.g., numbers, strings, boolean values).
  • Types include string literals (in quotes), numeric literals (integers, floats), boolean literals (True/False), special literal (None), collections (list, tuple, dictionary).

Operators

  • Operators perform operations on variables and values (e.g., +, -, *, /, //, %, **).
  • Categories: arithmetic, bitwise, comparison, logical, assignment, membership, identity.***

Punctuators

  • Punctuators are symbols that structure code (e.g., (), [], {}, :, ,, ;, @, #, quotes).

Structure of a Python Program (Bare Bones)

  • A program consists of expressions, statements, comments, indentation, and functions.
  • Indentation defines code blocks (four spaces or a tab).
  • Functions are reusable code blocks defined with def.

Variables and Assignment

  • Variables are references (labels) to stored values in memory.
  • Assignment uses = with variable name on the left and value on the right.
  • Supports multiple and dynamic assignments (type can change at runtime).

Input and Output Functions

  • Input with input() function (always returns a string; convert to int/float as needed).
  • Output with print() function (supports separators and end character).
  • Common escape sequences: \n (new line), \t (tab).

Key Terms & Definitions

  • Token β€” Smallest individual unit in a Python program.
  • Keyword β€” Reserved word with predefined meaning, not usable as identifiers.
  • Identifier β€” Name given to a variable, function, class, etc.
  • Literal β€” Fixed value written directly in code.
  • Operator β€” Symbol that performs operations on data.
  • Punctuator β€” Symbol used to structure Python code.
  • Variable β€” Named reference to a value stored in memory.
  • Assignment β€” Process of storing a value in a variable using =.
  • Indentation β€” Leading spaces or tabs that define code blocks.
  • Function β€” Reusable block of code defined with def.

Action Items / Next Steps

  • Practice writing Python programs using variables, input/output, and operators.
  • Review and memorize common keywords and token types.
  • Read Chapter 4 for practice-based questions.
  • Experiment with assignment, indentation, and block structures in code.