1/99
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.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
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.
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.
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).
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.
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).
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.
What are the six characteristics of a good program?
A good program should be Correct, Efficient, Readable, Modular, Maintainable, and Portable.
What is an algorithm?
An algorithm is a finite set of well-defined instructions to solve a problem or perform a task.
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).
What is pseudocode?
Pseudocode is a simple way to represent an algorithm using a mix of English and programming-like statements.
What components typically make up a complete programming environment?
A programming environment typically includes a Code Editor, Compiler/Interpreter, Linker, Debugger, and Runtime Environment.
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.
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.
In a flowchart, what does a parallelogram symbol represent?
A parallelogram represents Input or Output data entered or results displayed.
In a flowchart, what does a rectangle symbol represent?
A rectangle represents a Process or Instruction, indicating a calculation or processing step.
In a flowchart, what does a diamond symbol represent?
A diamond represents a Decision with two or more possible outcomes (such as Yes/No).
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.
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).
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.
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).
Who initially designed Python and when was it released?
Python was initially designed by Guido van Rossum in 1991.
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'.
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.
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).
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).
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.
Which Unix command makes a Python script file executable?
The command chmod +x myprogram.py makes the file executable.
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.
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.
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.
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.
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.
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.
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.
How are binary and hexadecimal integer literals represented in Python?
Binary literals start with 0b or 0B (e.g., 0b10 evaluates to 2), and hexadecimal literals start with 0x or 0X (e.g., 0X20 evaluates to 32).
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 10, such as 35e3 (35×103) or -87.7e100 (−87.7×10100).
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'>).
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.
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).
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.
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 """...""").
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.
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.
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').
How are Unicode strings designated in Python?
By preceding the opening quote with u or U (e.g., u'hello'), storing characters in 16 bits rather than 8 bits.
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.
What operators represent string concatenation and string repetition?
The plus sign + represents string concatenation, and the asterisk * represents string repetition.
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.
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.
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.
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.
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'.
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.
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.
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.
What are the seven arithmetic operators in Python?
The arithmetic operators are + (Addition), - (Subtraction), * (Multiplication), / (Division), % (Modulus), ** (Exponentiation), and // (Floor Division).
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.
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).
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).
What are the three logical operators in Python?
The logical operators are and, or, and not.
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.
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.
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.
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])).
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.
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.
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.
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.
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)).
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.
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.
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,.
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.
What is a Python Dictionary?
A Dictionary is an unordered, changeable, indexed collection of key-value pairs written with curly brackets {key: value}.
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.
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.
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.
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.
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.
What is the syntax for a one-line conditional expression in Python?
The syntax is true_value if Condition else false_value.
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.
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.
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.
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.
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.
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.
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.
Which values evaluate to False in Python Boolean contexts?
Numeric zero (0, 0.0), empty sequences ("", [], ()), empty dictionaries ({}), and None evaluate to False.
What keyword is used to define a function in Python?
The def keyword (e.g., def function_name():).
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__.
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.
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.
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.
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.
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).
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.
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.
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.
What is a recursive function in Python?
A recursive function is a function that calls itself until a base condition is satisfied.
What is a lambda function in Python?
A lambda function is an anonymous single-expression function defined using the syntax lambda args: expression.