Introduction to Computer Programming and Python Fundamentals

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/99

flashcard set

Earn XP

Description and Tags

Comprehensive practice flashcards created from lecture notes covering Computer Programming Fundamentals, Python Syntax, Data Types, Control Flow, Functions, Data Structures, File I/O, Modules, and Object-Oriented Concepts.

Last updated 1:56 PM on 9/6/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

100 Terms

1
New cards

What is programming?

Programming is the process of writing instructions that tell a computer what to do using a programming language that the computer can understand and execute.

2
New cards

What are the four primary reasons why programming is needed?

Programming is needed to solve problems efficiently, automate repetitive tasks, develop software/websites/games/mobile applications, and communicate with computers to perform useful work.

3
New cards

What are the four main components of a computer system?

The four main components are Hardware (physical components like CPU, memory, keyboard), Software (programs and operating systems), Data (facts and figures processed), and People (users who operate the computer).

4
New cards

What is a computer program?

A program is a set of step-by-step instructions written in a programming language to achieve a specific task following an Input \rightarrow Process \rightarrow Output sequence.

5
New cards

Into what three main categories are programming languages classified?

Programming languages are classified into Machine Language (low-level 0s and 1s), Assembly Language (uses mnemonics/short codes), and High-Level Language (easy for humans to write, like Python, Java, C).

6
New cards

What are the seven steps involved in program development?

The seven steps are: 1) Problem Definition, 2) Algorithm Design, 3) Coding, 4) Compilation / Interpretation, 5) Testing and Debugging, 6) Documentation, and 7) Maintenance.

7
New cards

What are the six characteristics of a good program?

A good program should be Correct, Efficient, Readable, Modular, Maintainable, and Portable.

8
New cards

What is an algorithm?

An algorithm is a finite set of well-defined instructions to solve a problem or perform a task.

9
New cards

What are the five characteristics of a good algorithm?

The five characteristics are Input (zero or more inputs), Output (at least one output), Definiteness (clear and unambiguous steps), Finiteness (terminates after finite steps), and Effectiveness (each step is basic and executable).

10
New cards

What is pseudocode?

Pseudocode is a simple way to represent an algorithm using a mix of English and programming-like statements.

11
New cards

What components typically make up a complete programming environment?

A programming environment typically includes a Code Editor, Compiler/Interpreter, Linker, Debugger, and Runtime Environment.

12
New cards

What is a flowchart?

A Flowchart is a graphical representation of an algorithm or a process that uses standard symbols connected by arrows to show the flow of control from one step to another.

13
New cards

In a flowchart, what does an oval (Terminator) symbol represent?

An oval symbol represents the Terminator, which indicates the beginning (Start) or end (Stop) of the flowchart.

14
New cards

In a flowchart, what does a parallelogram symbol represent?

A parallelogram represents Input or Output data entered or results displayed.

15
New cards

In a flowchart, what does a rectangle symbol represent?

A rectangle represents a Process or Instruction, indicating a calculation or processing step.

16
New cards

In a flowchart, what does a diamond symbol represent?

A diamond represents a Decision with two or more possible outcomes (such as Yes/No).

17
New cards

What is computer memory?

Computer memory is a storage area in a computer that stores data, instructions, and information either temporarily or permanently before, during, and after processing.

18
New cards

How does Primary Memory differ from Secondary Memory in accessibility, speed, and volatility?

Primary Memory is directly accessible by the CPU, very fast, and mostly volatile (RAM). Secondary Memory is not directly accessible by the CPU, slower, non-volatile (permanent), and has very high capacity (GBs to TBs).

19
New cards

What is the key difference between SRAM and DRAM?

SRAM (Static RAM) is faster, more expensive, and used in Cache memory. DRAM (Dynamic RAM) is slower, cheaper, and used in Main memory.

20
New cards

What are the three common types of Read Only Memory (ROM)?

The three types are PROM (Programmable ROM), EPROM (Erasable PROM), and EEPROM (Electrically Erasable PROM).

21
New cards

Who initially designed Python and when was it released?

Python was initially designed by Guido van Rossum in 1991.

22
New cards

From what source is the name 'Python' derived?

The name is derived from Guido van Rossum's favorite TV show, 'Monty Python's Flying Circus'.

23
New cards

On what specific dates were Python 2.0 and Python 3.0 released?

Python 2.0 was released on October 16, 2000, and Python 3.0 was released on December 3, 2008.

24
New cards

What is Python's traditional runtime execution model?

Source code (.py) is automatically compiled into byte code (.pyc), which is then interpreted and run by the Python Virtual Machine (PVM).

25
New cards

What are the two modes available for using the Python interpreter?

Interactive Mode (direct execution at prompt) and Script Mode (executing source code saved in a .py file).

26
New cards

How do you specify the location of the Python interpreter in a Unix shebang line?

By including a comment as the first line of the file starting in column 1, such as #!/usr/local/bin/python.

27
New cards

Which Unix command makes a Python script file executable?

The command chmod +x myprogram.py makes the file executable.

28
New cards

In Python interactive mode, what function allows you to execute a stored Python file?

The execfile("myprog.py") function executes a file containing a Python program when running interactively.

29
New cards

How can an interactive Python session be terminated?

By entering the end-of-file character (Control-Z for Windows, Control-D for Unix), or entering import sys; sys.exit() or raise SystemExit at the prompt.

30
New cards

Why does Python use indentation instead of curly braces or keywords like 'begin' and 'end'?

Python uses indentation (whitespace) to indicate the presence of loops and code blocks, ensuring clean, readable, and consistent syntax across programs.

31
New cards

What are the rules for naming variables in Python?

Variable names must start with a letter or underscore _, cannot start with a number, can only contain alphanumeric characters and underscores (A-z, 0-9, _), and are case-sensitive.

32
New cards

What is dynamic typing in Python?

Dynamic typing means Python automatically detects and assigns the data type of a variable at runtime based on the value assigned to it.

33
New cards

How can multiple variables be assigned values simultaneously in Python?

Multiple variables can be assigned values at once using comma separation, such as x, y, z = 10, 20, 30 or a = b = c = 1.

34
New cards

What are the properties of Python integers (int)?

An integer is a whole number, positive or negative, without decimals, and of unlimited length in Python.

35
New cards

How are binary and hexadecimal integer literals represented in Python?

Binary literals start with 0b or 0B (e.g., 0b10 evaluates to 22), and hexadecimal literals start with 0x or 0X (e.g., 0X20 evaluates to 3232).

36
New cards

How are scientific numbers represented as floats in Python?

Floats can be written in scientific notation using an e or E to indicate the power of 1010, such as 35e3 (35×10335 \times 10^3) or -87.7e100 (87.7×10100-87.7 \times 10^{100}).

37
New cards

What function is used to verify or check the data type of an object in Python?

The type() function (e.g., type(10) returns <class 'int'>).

38
New cards

Which built-in functions perform explicit conversion to integer, float, and string?

The functions int(), float(), and str() convert values to integer, float, and string data types respectively.

39
New cards

How are complex numbers represented in Python?

Complex numbers are denoted as a real part plus an imaginary part with a trailing j or J (e.g., 3.2 + 7j), or created using complex(real, imag).

40
New cards

What does the coerce() function do in Python?

The coerce(x, y) function converts the numeric argument lower in the hierarchy (integer, long, float, complex) to the type of the argument higher in the hierarchy.

41
New cards

What three quote styles can be used to create string constants in Python?

Strings can be surrounded by single quotes ('...'), double quotes ("..."), or triple quotes ('''...''' or """...""").

42
New cards

What is the purpose of placing a backslash (\) before a quote inside a string?

It escapes the quote character, suppressing its normal string-delimiter meaning and interpreting it as a literal quote character.

43
New cards

What do the escape sequences \n, \t, and \\ represent in Python strings?

\n represents a newline, \t represents a horizontal tab, and \\ represents a literal backslash.

44
New cards

What is a raw string in Python and how is it constructed?

A raw string treats backslashes as literal characters rather than escape sequences; it is constructed by preceding opening quotes with r or R (e.g., r'c:\newline').

45
New cards

How are Unicode strings designated in Python?

By preceding the opening quote with u or U (e.g., u'hello'), storing characters in 1616 bits rather than 88 bits.

46
New cards

What does string immutability mean in Python?

Immutability means string objects cannot be altered in place after creation; item assignment like greeting[0] = 'n' produces a TypeError.

47
New cards

What operators represent string concatenation and string repetition?

The plus sign + represents string concatenation, and the asterisk * represents string repetition.

48
New cards

What is the general syntax for string and list slicing in Python?

The syntax is sequence[start:stop:steps], slicing from index start up to but not including stop in steps of steps.

49
New cards

How do negative indices function in Python sequence indexing?

Negative indices count backward from the end of the sequence, where [-1] represents the last item.

50
New cards

What function returns the number of characters in a string or items in a sequence?

The len() function returns the length of a string or sequence.

51
New cards

What do the formatting codes %d, %f, %s, and %g represent in Python string formatting?

%d represents decimal integer, %f represents floating point number, %s represents string, and %g represents optimal floating point notation.

52
New cards

What is the syntax for a formatted string literal (f-string) in Python?

An f-string is created by prefixing the string with f or F and enclosing expressions in curly braces, such as f'{first_name} [{last_name}] is a coder'.

53
New cards

What does the string split() method do?

The split() method splits a string according to a delimiter (default is whitespace) and returns a list of substrings.

54
New cards

What does the string join() method do?

The join(sequence) method inserts the string on which it is called between each string element of the given sequence, returning a single combined string.

55
New cards

What do string methods lstrip(), rstrip(), and strip() remove?

lstrip() removes leading whitespace, rstrip() removes trailing whitespace, and strip() removes both leading and trailing whitespace.

56
New cards

What are the seven arithmetic operators in Python?

The arithmetic operators are + (Addition), - (Subtraction), * (Multiplication), / (Division), % (Modulus), ** (Exponentiation), and // (Floor Division).

57
New cards

What is the difference between division / and floor division // in Python?

Division / carries out true division returning a float, whereas floor division // truncates the decimal part and returns the integer quotient.

58
New cards

What are augmented assignment operators?

Augmented assignment operators combine an arithmetic operation with assignment, such as +=, -=, *=, and /= (e.g., x += 3 is equivalent to x = x + 3).

59
New cards

What are the six comparison operators in Python?

The comparison operators are == (Equal To), != (Not Equal To), > (Greater Than), < (Less Than), >= (Greater Equal), and <= (Less Equal).

60
New cards

What are the three logical operators in Python?

The logical operators are and, or, and not.

61
New cards

What is short-circuit evaluation in Python logical expressions?

Short-circuit evaluation means Python evaluates logical expressions left-to-right only until the overall truth value is determined; remaining expressions are not evaluated.

62
New cards

What do the membership operators in and not in test?

They test whether a specified value or object is present or absent within a collection or sequence.

63
New cards

How does the == operator differ from the is operator?

The == operator tests if two objects contain equal values, whereas the is operator tests if two variables reference the exact same object in memory.

64
New cards

Which module provides support for fixed-type numeric and character arrays in Python?

The array module (e.g., from array import *; array1 = array('i', [10, 20, 30])).

65
New cards

What do array typecodes 'b', 'i', 'f', and 'd' represent?

'b' represents signed 1-byte integer, 'i' represents signed 2-byte integer, 'f' represents 4-byte float, and 'd' represents 8-byte float.

66
New cards

What are the primary characteristics of a Python List?

A List is an ordered, changeable (mutable) collection that allows duplicate members, grows or shrinks as needed, and can hold mixed data types.

67
New cards

How do list.append(x) and list.extend(sequence) differ?

append(x) appends object x as a single item at the end of the list, whereas extend(sequence) appends each element of sequence to the list.

68
New cards

What does list.pop(i) do compared to list.remove(x)?

pop(i) removes and returns the element at index i (defaulting to the last item), whereas remove(x) removes the first occurrence of item x by value.

69
New cards

What is list aliasing versus list cloning?

Aliasing occurs when two variables reference the same list object (b = a), so changes affect both; cloning creates an independent copy (b = a[:] or copy.copy(a)).

70
New cards

What is the general syntax for a List Comprehension?

The syntax is [expression for var in sequence if condition], providing a concise way to create new lists from existing sequences.

71
New cards

What is a Python Tuple and how is it defined?

A Tuple is an ordered, unchangeable (immutable) sequence of items written with round brackets (...) or comma-separated values.

72
New cards

How must a single-element tuple be declared in Python?

A single-element tuple must be declared with a trailing comma following the element, such as (7,) or 7,.

73
New cards

What object type is created by a tuple comprehension (i for i in 'abc')?

A tuple comprehension creates a generator object that can be iterated over once, rather than a tuple.

74
New cards

What is a Python Dictionary?

A Dictionary is an unordered, changeable, indexed collection of key-value pairs written with curly brackets {key: value}.

75
New cards

What requirement must be met by keys in a Python Dictionary?

Dictionary keys must be unique and immutable objects (such as strings, numbers, or tuples). Mutable objects like lists cannot be used as keys.

76
New cards

Which dictionary methods return views of keys, values, and key-value pairs?

The methods dict.keys() returns keys, dict.values() returns values, and dict.items() returns key-value tuple pairs.

77
New cards

What does dict.get(key, default) return if the key is not present in the dictionary?

It returns the optional default value (or None if omitted), preventing a KeyError exception.

78
New cards

How does dict.update(other_dict) behave when keys overlap?

It updates the target dictionary with key/value pairs from other_dict, overwriting existing values for matching keys.

79
New cards

What are the three conditional statement structures in Python?

The structures are single conditional if, alternative conditional if-else, and chained conditional if-elif-else.

80
New cards

What is the syntax for a one-line conditional expression in Python?

The syntax is true_value if Condition else false_value.

81
New cards

How does a while loop operate in Python?

A while loop repeatedly executes a block of statements as long as its Boolean conditional expression evaluates to True.

82
New cards

How does a for loop operate in Python?

A for loop iterates over the items of any sequence or iterable collection (lists, tuples, strings, dictionaries), executing the block for each item.

83
New cards

When is the optional else clause of a loop executed?

The else clause attached to a for or while loop is executed when the loop finishes iterating naturally, but not if the loop is terminated by a break statement.

84
New cards

What is the difference between range() and xrange() in Python?

range() creates and stores the entire list of integers in memory, while xrange() calculates numbers on demand as an iterator, conserving memory for large ranges.

85
New cards

What does the break statement do inside a loop?

The break statement immediately terminates the loop containing it, transferring control to the statement directly following the loop.

86
New cards

What does the continue statement do inside a loop?

The continue statement skips the rest of the code inside the loop for the current iteration and jumps directly to the next iteration.

87
New cards

What is the pass statement in Python?

The pass statement is a null statement used as a placeholder for functionality to be added later; unlike comments, it is executed by the interpreter.

88
New cards

Which values evaluate to False in Python Boolean contexts?

Numeric zero (0, 0.0), empty sequences ("", [], ()), empty dictionaries ({}), and None evaluate to False.

89
New cards

What keyword is used to define a function in Python?

The def keyword (e.g., def function_name():).

90
New cards

What is a docstring and how is it accessed?

A docstring is a documentation string placed as the first line inside a function header; it is accessed via function_name.__doc__.

91
New cards

What is the distinction between a parameter and an argument?

A parameter is a variable defined in a function header, whereas an argument is the actual value passed to the function when it is called.

92
New cards

What rule governs default parameter values in function definitions?

Non-default parameters cannot follow default parameters; once a parameter has a default value, all parameters to its right must also have default values.

93
New cards

How do keyword arguments differ from positional arguments during a function call?

Keyword arguments explicitly pass values using parameter names (param=value), allowing any order, while positional arguments assign values based on position.

94
New cards

How do *args and **kwargs capture arbitrary arguments in function definitions?

*args collects non-keyworded variable-length arguments into a tuple, while **kwargs (or **dict) collects keyworded variable-length arguments into a dictionary.

95
New cards

What is a fruitful function versus a void function?

A fruitful function returns an explicit value using a return statement, whereas a void function does not return a value (returning None).

96
New cards

What is dead code in a Python function?

Dead code refers to statements that appear after a return statement or in locations where the flow of execution can never reach.

97
New cards

What is the LGB scoping rule in Python?

Python searches for variable names first in the Local namespace, then in the Global namespace, and finally in the Built-in namespace.

98
New cards

How can a local variable inside a function modify a global variable?

By declaring the variable name with the global keyword inside the function prior to modification.

99
New cards

What is a recursive function in Python?

A recursive function is a function that calls itself until a base condition is satisfied.

100
New cards

What is a lambda function in Python?

A lambda function is an anonymous single-expression function defined using the syntax lambda args: expression.