CS 1301 FINAL STUDY GUIDE

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/61

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

62 Terms

1
New cards

Python

A high-level, readable programming language.

2
New cards

Purpose of Python

To write programs for automation, web development, data analysis, etc.

3
New cards

Example of Python code

print("Hello, world!")

4
New cards

Variables

Containers for storing data values.

5
New cards

Purpose of Variables

To store and reuse values throughout a program.

6
New cards

Example of Variable

x = 10

7
New cards

Types

Classifications of data (int, float, str, etc.).

8
New cards

Purpose of Data Types

To define what kind of data is being used.

9
New cards

Example of Data Types

age = 18 (int), name = "Sam" (str)

10
New cards

Branching

Allows decision-making using conditions.

11
New cards

Purpose of Branching

To execute different code paths based on logic.

12
New cards

Example of Branching

if x > 10:\n print("Big")

13
New cards

While Loop

Repeats a block of code as long as a condition is true.

14
New cards

Purpose of While Loop

Useful when the number of iterations isn't known.

15
New cards

Example of While Loop

while x < 5:\n x += 1

16
New cards

For Loop

Iterates over a sequence (like a list or range).

17
New cards

Purpose of For Loop

To repeat tasks a known number of times or over collections.

18
New cards

Example of For Loop

for i in range(5):\n print(i)

19
New cards

Functions

Reusable blocks of code with a name.

20
New cards

Purpose of Functions

To organize code and perform tasks multiple times.

21
New cards

Example of Function

def greet():\n print("Hi!")

22
New cards

Strings

Text data enclosed in quotes.

23
New cards

Purpose of Strings

To store and manipulate text.

24
New cards

Example of String

msg = "Hello"

25
New cards

Lists / Dicts

List: ordered collection; Dict: key-value pairs.

26
New cards

Purpose of Lists / Dicts

To store multiple items in a single variable.

27
New cards

Example of List and Dict

fruits = ["apple", "banana"], person = {"name": "Alice"}

28
New cards

Classes

Blueprint for creating objects (OOP).

29
New cards

Purpose of Classes

To model real-world entities and use object-oriented principles.

30
New cards

Example of Class

class Dog:\n def init(self, name):\n self.name = name

31
New cards

Exceptions

Errors caught and handled during execution.

32
New cards

Purpose of Exceptions

To make code more robust by handling errors gracefully.

33
New cards

Example of Exception handling

try:\n x = 1/0\nexcept ZeroDivisionError:

34
New cards

Modules

Files containing Python code (functions, classes, etc.).

35
New cards

Purpose of Modules

To organize and reuse code across files.

36
New cards

Example of Importing a Module

import math\nprint(math.sqrt(4))

37
New cards

Files

Input/output operations on text/binary files.

38
New cards

Purpose of Files

To read from or write to external files.

39
New cards

Example of File Operation

with open("file.txt") as f:\n print(f.read())

40
New cards

Plotting

Visual representation of data (often using libraries).

41
New cards

Purpose of Plotting

To analyze and visualize data.

42
New cards

Example of Plotting

import matplotlib.pyplot as plt\nplt.plot([1,2,3],[4,5,6])\nplt.show()

43
New cards

Python Introduction

Python is used for algorithms and machine learning.

44
New cards

Python Execution Model

Python is both compiled and interpreted.

45
New cards

Syntax Error

Occurs when the program contains invalid code that can't be understood.

46
New cards

Identifiers

Variable names that cannot use reserved words.

47
New cards

Arithmetic Operators

Normal division keeps remainder (/), floor division removes it (//).

48
New cards

Python Core Data Types

Lists, integers, strings, dictionaries, tuples, boolean, sets.

49
New cards

Purpose of Len

Counts the number of elements or characters in a list or string.

50
New cards

Negative Indexing

Starts with 1 and counts down instead of starting from 0.

51
New cards

Insert Method (lists)

Assigns an index to a value in a list.

52
New cards

Example of Insert Method

my_list.insert(2,67) replaces index 2 with the value 67.

53
New cards

Tuples

Cannot be updated or changed; store finalized data.

54
New cards

Updating a Tuple

Convert tuple to list first, then update.

55
New cards

Dictionary Deletion

Use del to remove an item from a dictionary.

56
New cards

Example of Dictionary Deletion

del d1["John"]

57
New cards

Retrieval from Dictionary

Use d1.get("Susan") to get a value.

58
New cards

Check Membership in List

Use syntax 15 in my_list to check if value exists.

59
New cards

If Statements

No else required, but else needs a corresponding if.

60
New cards

Blocks in Python

Represented by indentation.

61
New cards

Assignment vs Equality

= is for assigning notations, while == is for equality checks.

62
New cards

If Statement Execution

Executes code below if condition is true, else moves on.