NONESENSE MID TERM FOP

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/44

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.

45 Terms

1
New cards

Selection Structures

Allow you to make decisions and execute different code blocks based on certain conditions. They enable your program to choose between alternative paths of execution, making programs dynamic and responsive.

2
New cards

Conditional Statements

Also known as decision-making statements. Evaluate a condition and execute different code blocks based on the result. Fundamental for decision-making in Python. Types: if, if-else, if-elif-else, switch (or elif used in Python).

3
New cards

If Statement (One-way Selection)

Executes a block of code only if a specified condition is True. If False, the block is skipped and the program continues. Syntax example: if condition: statement.

4
New cards

If-Else Statement (Two-way Selection)

Extends the if statement by providing an alternative code block when the condition is False. Executes one block if True, another if False.

5
New cards

If-Elif-Else Statement (Multi-way Selection)

Evaluates multiple conditions sequentially. Used when there are more than two possible outcomes. Creates decision trees and allows complex decision-making.

6
New cards

Nested Decision Making

Placing one or more if…else statements inside another. Used when multiple conditions need to be tested sequentially. Adds flexibility for complex program logic.

7
New cards

Relational (Comparison) Operators

Used to compare values and determine relationships. Examples: == (equal), != (not equal), > (greater than), < (less than), >= (greater or equal), <= (less or equal).

8
New cards

Boolean (Logical) Operators

Used to combine or manipulate boolean values. and → True if both operands are True. or → True if at least one operand is True. not → reverses logical state. Supports short-circuit evaluation for efficiency.

9
New cards

Short-Circuit Evaluation

Python evaluates logical expressions from left to right and stops when the result is known (e.g., in “and” if first is False, in “or” if first is True). Improves code efficiency.

10
New cards

Iterative Structures (Loops)

Allow repeating code blocks multiple times under specific conditions. Used to automate repetitive tasks and control program flow efficiently. Two main types: while and for loops.

11
New cards

While Loop

Repeats a block of code as long as a condition is True. Commonly used for reading input, data traversal, or iterative algorithms. Stops when the condition becomes False.

12
New cards

For Loop

Executes a block of code for each element in a sequence (list, tuple, string, or range). Ideal when the number of iterations is known. Syntax: for item in sequence: statements.

13
New cards

Loop Structure

Loop header defines iterations and ends with a colon (:). The loop body (indented lines) executes repeatedly per iteration. When the condition becomes False, the loop stops.

14
New cards

Nested Loops

Loops inside another loop. The inner loop runs multiple times for each iteration of the outer loop. Used for multidimensional data, pattern generation, and complex algorithms.

15
New cards

Break Statement

Used to exit a loop immediately even if its condition hasn’t become False. Helps improve efficiency by stopping unnecessary iterations once a condition is met.

16
New cards

Importance of Break

Used to exit early when conditions are met, to skip redundant code, or to exit nested loops for efficiency and performance.

17
New cards

Continue Statement

Skips the rest of the code in the current loop iteration and moves to the next iteration. Useful for bypassing unwanted steps while still continuing the loop.

18
New cards

Importance of Continue

Improves efficiency by avoiding unnecessary operations. Useful in filtering or skipping specific data within loops.

19
New cards

List

A mutable, ordered collection of elements (integers, strings, etc.). Allows storing and organizing data sequences and modifying them dynamically.

20
New cards

Purpose of Lists

  1. Grouping related data. 2. Dynamic resizing. 3. Easy iteration and processing of elements. Lists are essential for organizing, processing, and iterating over data.
21
New cards

Creating a List

Use square brackets [ ] and separate elements with commas. Lists can contain mixed data types.

22
New cards

Accessing List Elements

Elements are accessed using indices starting from 0. Example: list[0] for first element, list[-1] for last.

23
New cards

List Operators and Functions

Examples: L[i] – access by index; L[start:end] – slicing; L1 + L2 – concatenation; len(L) – number of elements; print(L) – display list; value in L – membership test.

24
New cards

List Methods (Insertion and Removal)

L.append(x) adds to end. L.extend(aList) adds another list. L.insert(i,x) inserts at position. L.pop() removes last item; L.pop(i) removes at index.

25
New cards

Searching and Sorting in Lists

in operator checks existence. index() returns element position. L.sort() arranges elements in ascending order.

26
New cards

Mutator Methods for Lists

insert(), append(), extend(), pop(), and sort() — these modify lists directly.

27
New cards

Importance of Lists

Provide dynamic storage, easy iteration, and organization of heterogeneous data. Core Python data structure for algorithms and applications.

28
New cards

Dictionaries

Mutable, unordered collections of key:value pairs. Keys are unique and associated with values. Written inside curly braces {key:value}.

29
New cards

Purpose of Dictionaries

Used for fast lookup, association, and data mapping (e.g., storing records or configurations).

30
New cards

Adding and Replacing Values in Dictionaries

Use d[key] = value to insert or update. If key exists, value is replaced; if not, key is added.

31
New cards

Accessing Values in Dictionaries

Use d[key] to get a value or d.get(key, default) to avoid KeyError. Use “key in d” to check existence.

32
New cards

Removing Keys from Dictionaries

Use d.pop(key[,default]) to remove and return value; d.clear() to remove all items.

33
New cards

Traversing a Dictionary

for key in d: loops through all keys. list(d.keys()), list(d.values()), list(d.items()) return lists of keys, values, and key-value tuples.

34
New cards

Dictionary Operations

len(d) – count entries. list(d.keys()) – all keys. list(d.values()) – all values. list(d.items()) – key:value tuples.

35
New cards

Importance of Dictionaries

Organize data efficiently using key-value mapping; enable fast data retrieval and structured storage.

36
New cards

Tuples

Ordered, immutable collections of elements. Similar to lists but cannot be changed after creation. Efficient and used for fixed data.

37
New cards

Tuple Packing and Unpacking

Packing: assigning multiple values into one tuple. Unpacking: extracting tuple elements into separate variables.

38
New cards

Basic Tuple Operations

Concatenation (+), repetition (*), and membership test (in). Tuples support indexing and iteration like lists.

39
New cards

Practical Uses of Tuples

Ensure data integrity (immutable), allow returning multiple values from functions, and define named tuples for readability.

40
New cards

Sets

Unordered collections storing unique elements only. Created with braces {} or set(). Do not allow duplicates.

41
New cards

Common Uses of Sets

Eliminate duplicates, perform fast membership testing, and find common elements (intersection) between sets.

42
New cards

Set Methods

.add() – add element; .clear() – remove all; .copy() – copy set; .difference() – elements not in others; .intersection() – common elements; .union() – combine sets; .update() – add elements from another iterable.

43
New cards

Advanced Set Methods

.differenceupdate() removes overlapping items; .discard(x) removes item if present; .isdisjoint(), .issubset(), .issuperset() test relationships; .symmetricdifference() returns non-common elements.

44
New cards

Comparison of Data Structures

List → ordered, changeable, allows duplicates. Dictionary → key-ordered, mutable, keys unique. Tuple → ordered, immutable. Set → unordered, unique elements only.

45
New cards