Study guide: Python Programming Fundamentals

Course Outline

  1. Python Origins and Key Features
  2. Python Uses and Applications
  3. Interactive Python Tools
  4. Python Statements and Indentation
  5. Variables, Identifiers, and Input Output
  6. Python Built-In Data Types
  7. Arithmetic and Assignment Operators
  8. Comparison and Logical Operators
  9. Identity and Membership Operators
  10. Python Bitwise Operators

1. Python Origins and Key Features

★ Must-know

  • Guido van Rossum began developing Python in late 1989, naming it after the British comedy group Monty Python.

  • Python 0.9.0 included: functions, exception handling, lists, strings, dictionaries, modules

  • Python is:

    • interpreted
    • dynamically typed
    • cross-platform
    • open-source
    • high-level
    • designed for readable syntax

Further detail

  • Python 1.0 was officially released in 1994 with functional tools such as map(), filter(), and reduce(), as well as modules, classes, and exception handling.

  • Python supports these programming paradigms:

    • procedural
    • object-oriented
    • functional
  • Python can be extended with C or C++ code and is described as portable, integrated, easy to debug, and usable for frontend and backend development.

2. Python Uses and Applications

★ Must-know

  • Python is used in:
    • data science
    • machine learning
    • web development
    • scientific computing
    • automation

Further detail

  • NumPy, pandas, and Matplotlib support data analysis and visualization, while TensorFlow and PyTorch are used for machine learning.

  • Django, Pyramid, and Flask are Python web application frameworks, and Python web applications can be hosted by Apache, IIS, and Nginx.

  • OpenCV, a C++ library ported to Python, is used for image processing tasks such as face detection and gesture recognition.

  • PyGame is used to build desktop and mobile games, and PyGame applications can also be installed on Android.

  • Python is used with Raspberry Pi and Arduino in embedded systems, automation, robotics, and IoT applications.

  • Python scripts can automate recurring tasks such as backups by scheduling them to run at predefined times.

  • Jython interacts with Java libraries and IronPython interacts with C#; Jython can use Java libraries such as Swing for rapid prototyping.

3. Interactive Python Tools

Key Concepts & Definitions

  • REPL: An interactive environment that reads and executes code one line at a time, displays the result, and repeats the process.
  • IDLE: An IDE included with the standard Python installation.

Essential Points

  • 🔄 A REPL interaction proceeds by:

    1. reading the user's code
    2. evaluating it
    3. printing the result
    4. repeating the cycle
  • On Windows, typing python at the command prompt and pressing Enter opens the Python shell, whose prompt is >>>.

  • IDLE provides an interactive shell, a script editor with syntax highlighting, auto-completion and line numbers, and a debugger with breakpoints, stepping, and variable viewing.

  • IDLE runs on Windows, macOS, and Linux, and scripts can be run from its editor by pressing F5 or selecting Run Module.

Memory Hook

REPL is the interactive prompt; IDLE adds an editor and debugger.

4. Python Statements and Indentation

Key Concepts & Definitions

  • Indentation: Leading whitespace that determines the grouping of Python statements into blocks.

★ Must-know

  • A Python statement normally ends at a NEWLINE character, so each physical line is a separate statement unless line continuation is used.

  • A backslash joins physical lines into one logical statement, while a semicolon separates multiple statements written on one line.

  • A Python block starts after a colon, and all statements in the block must use consistent indentation; Python recommends four spaces and warns against mixing spaces and tabs.

Further detail

📌 Expressions inside parentheses, square brackets, or curly braces can span multiple lines without backslashes.

5. Variables, Identifiers, and Input Output

Key Concepts & Definitions

  • Variable: A named location in memory used to store data, with its type inferred by Python from the assigned value.

★ Must-know

📌 An identifier must start with a letter or underscore and may then contain letters, digits, or underscores; identifiers are case-sensitive and cannot be reserved keywords.

📌 The assignment operator = assigns a value to a variable, and Python supports both multiple-target assignment such as a, b = 1, 2 and chained assignment such as x = y = 0.

  • The input() function returns user input as a string, so numeric input must be converted with functions such as int() or float() when needed.

Further detail

  • Python naming conventions use: TitleCase for class names, lowercase with underscores for function names, lowercase with underscores for module names, uppercase for constants, double leading and trailing underscores for special names such as init

  • Python displays console output with print(), which supports f-strings, str.format(), percent formatting, and custom end and sep arguments.

6. Python Built-In Data Types

Key Concepts & Definitions

  • Integer: A positive or negative whole number without a decimal part, with no fixed length limit in Python.
  • Float: A positive or negative number with a decimal part that may also use e notation to represent a power of ten.
  • Boolean: A Boolean (bool) represents one of two values, True or False, and is used in conditional logic.
  • String: A sequence of characters enclosed in single, double, or triple quotes.

7. Arithmetic and Assignment Operators

Key Concepts & Definitions

  • Arithmetic Operators: Arithmetic operators perform mathematical operations on numeric operands, and the result type depends on both the operator and the operand types: for addition, subtraction, and multiplication, the result is complex if either operand is complex, floating point if either is a float, and integer if both are integers.
  • Assignment Operators: Assignment operators assign values to variables, including augmented forms such as +=, -=, *=, /=, //=, %=, ^=, &=, |=, >>=, and <<=.

★ Must-know

  • Python arithmetic operators include:
    • addition +
    • subtraction -
    • multiplication *
    • exponentiation **
    • division /
    • floor division //
    • modulus %

Further detail

  • For positive integers, 11 % 3 gives the remainder 2, while 6 // 5 gives the floor-division result 1.

8. Comparison and Logical Operators

Key Concepts & Definitions

  • Comparison Operators: Operators that compare two operands and return a Boolean value, True or False.
  • Logical Operators: The logical operators and, or, and not combine or negate Boolean expressions.

Essential Points

  • Python comparison operators are >, <, ==, !=, >=, and <=.

9. Identity and Membership Operators

Key Concepts & Definitions

  • Identity Operators: The identity operators is and is not test whether two objects refer to the same memory location.
  • Membership Operators: The membership operators in and not in test whether a sequence contains a specified item; for strings and bytes, x in y is true exactly when x is a substring of y.

Essential Points

  • The expression 1 in [1, 2, 3, 4, 5] evaluates to True, while 1 not in [1, 2, 3, 4, 5] evaluates to False.

Memory Hook

Equality compares values; identity checks whether objects share the same memory location.

10. Python Bitwise Operators

Key Concepts & Definitions

  • Bitwise Operators: Operators that perform operations on binary operands.

★ Must-know

  • The bitwise operators perform:
    • & for AND
    • | for OR
    • ^ for exclusive OR
    • ~ for bit inversion

Further detail

  • The left-shift operator << shifts bits left by inserting zeros on the right without dropping leftmost bits in Python, while the right-shift operator >> shifts right by copying the leftmost bit from the left and dropping rightmost bits.

  • For x = 5, x << 2 evaluates to 20 and x >> 2 evaluates to 1.

Test yourself

Take a 19-question practice quiz on Python Programming Fundamentals, with every answer explained.

1. Regarding Python’s origins, which statements are accurate?

2. Which areas are established applications of Python?

Take the quiz →

Study with flashcards

Memorize the key concepts of Python Programming Fundamentals with 66 flashcards.

When did Guido van Rossum begin developing Python?

In late 1989.

What inspired the name Python?

The British comedy group Monty Python.

When was Python 0.9.0 released?

February 1991.

See the flashcards →

Related classes

Make your own study guides

Upload your class notes and Revizly writes a study guide, a quiz and flashcards in about a minute.

Study guide maker