Study guide for FOP

About This Study Guide

This study guide was created by one of your peers for Foundations of Programming (FOP). It covers all six domains of the course. The information was gathered from GMetrix instructional videos and supplemental resources such as GeeksforGeeks and other programming references.

Core concepts are displayed openly in each section. Additional details and practice questions are available in expandable sections that can be opened by clicking the “Details” or “Practice Questions” buttons at the bottom of each topic.

Code examples are included throughout the guide. You are encouraged to copy and run the code to test your understanding as you work through the material.

Layout Structure

Study Guide
Domain
Subsections within each domain

Each domain contains structured explanations, examples, and review questions to help reinforce understanding.

I am currently still working on this it not yet complete


Domain 1 Operations using data

Domain 1 covers variables and naming rules, data types (including lists), type casting functions, arithmetic operators, comparison operators, logical keywords, identity operators, membership operators

Variables

Variables are container of data, like text numbers true or false values, and even other Variables.

Rules for Naming Variables

To use variables effectively, we must follow Python’s naming rules:

  1. Variable names can only contain letters, digits and underscores (_).
  2. A variable name cannot start with a digit.
  3. Variable names are case-sensitive like myVar and myvar are different.
  4. Avoid using Python keywords like if, else, for as variable names.

"this is from GeeksforGeeks"

best practices when making variables is to use camel casing; the first letter of the first word is lowercase and any subsequent words start with a capital letter. (from the videos)

according to the video (second video named Evaluate Data Types: Time -0.02 ) Python is a loosely typed language, meaning variables do not need to be declared before they are used.

this information is wrong python is not a loosely typed language it is a strong typed language, and you can't use a variable before it declared.
A strong typed language means; a programming language that enforces strict rules regarding the use of variable types, preventing the mixing of different types in operations and assignments.

Variables can be String, Int, Float, Bool, list.

  • Strings: a string is a variable that allows you to hold text, text is numbers letters emojis symbols. you can use any symbol in the UTF-8 encoding of Unicode.
  • Int: a int is variable that allows you to hold whole numbers Ex 1 2 3.
  • Float: a float is a variable that allows you to hold real numbers Ex 1.25 2.568 3.1231 but there is a limit to the point precision (how accurate it is after the . ) Explanation at GeeksforGeeks
  • Bool: a bool also know as a boolean is a True or false variable meaning it can only hold true or false, in python you have to uppercase the first letter of the true or false word if not it a syntax Error. List a list is a collection of other variables the list can be mixed of different data types.
 s = "this is a string" # a string can also be made with single quotes in python
 i = 123 # this is a int
 f = 1.0 # this is a float
 b = True # this is a bool
 l = [s,i,f,b] # this is a list
 for item in l:
    print(item)

Data types

A data type is the type of data a variable has.
Ex: name = "Jason"
The variable name has a data type of string, and holds data "Jason"
String, Int, Float, Bool, and List are all data types. There are more data types but those are the only ones covered in domain one.
I already explained data types in the section above well so I won't again.

Comparison operators

A comparison operator is used to compare.
From the video we have 6 comparison operators.

  • == Equality check if both side are equal to each other.
  • > Gather then check if the left side is bigger then the right side.
  • < Less then check if the left side is smaller then the right side.
  • >= Gather then or equal check if the left side is bigger then or equal to the right side.
  • <= Less then or equal check if the left side is smaller or equal to the right side.
  • != Not equal check if there not equal to each other.

All these operators return a bool as a result.

List

List are a collection of variables (data)
You can make a list by surrounding the data with [] and having commands between the data.
Ex: a = ["test 1", "test 2", 1, 2, 3]

List start at index 0 and go up by 1.
Ex: a = ["test", 1, 1.2, True]
In list a "test" is at index 0 and True is at index 3.
List can growth and shrink in length as you want.

To grab data from a list you do list name[] and inside the [] you put the index you can also use negative numbers starting form -1 to -length of list.
You can get the length of a list with len(). For this example we will use the a list form before
len(a) will return 4 since the length of the list is 4.
If you try to do a[4] you will get a out of bounds Error. Do you know why.

You can add data with append (append add data to the end of the list) or insert (insert add data to the index you give.)
You can remove data with pop (pop removes the index you give it and returns the item at that index. If no index is given it does it at the end of a list) or remove (remove removes the first instances of the given value).

You can sort list with sort it sorts from least to greatest or alphabetical.