1/33
Comprehensive review flashcards covering programming definitions, Python syntax, error types, variable rules, data types, type casting, string operations, and conditional control structures.
Who created the Python programming language, and in what year was it first released?
Guido van Rossum released Python in 1991.
What are the four primary application areas for Python listed in the lecture?
Web development (server-side), software development, mathematics, and system scripting.
How is a "program" formally defined in the context of computer programming?
A program is a sequence of instructions that specifies how to perform a computation, which may be mathematical or symbolic.
What are the six core components or operations involved in programming?
Input, output, math, conditional execution, repetition, and algorithms.
What historical origin is cited for the use of the term "bug" to describe engineering difficulties?
It dates back to at least 1889, when Thomas Edison reported a bug with his phonograph.
What are the three distinct categories of programming errors?
Syntax errors, runtime errors (exceptions), and semantic errors.
What characterizes a semantic error in a program?
The program executes successfully without generating error messages, but it does not perform the intended task; the meaning (semantics) of the program is incorrect.
Why are runtime errors also referred to as exceptions?
Because they do not appear until the program runs and usually indicate that something exceptional and bad has occurred.
What role does indentation play in Python compared to many other programming languages?
Python uses indentation (whitespace at the start of a line) to define code blocks and scope, whereas other languages often use curly brackets.
What are the rules regarding the number of indentation spaces required in a Python code block?
The programmer can choose the number of spaces, but there must be at least 1 space (with 4 being the most common standard), and all statements within the same block must use the exact same number of spaces.

What error occurs in the provided code snippet, and why?
Python raises a Syntax Error (specifically an IndentationError) because the two print statements inside the same code block do not use the same number of spaces.
How can a developer create a multiline comment in Python without placing a "#" symbol on each line?
By using an unassigned multiline string literal enclosed in triple quotes (""" or '''), which Python reads but ignores during execution.
How does Python handle variable declaration and data typing?
Python has no declaration command; a variable is created the moment a value is assigned to it, and variables can dynamically change type after being set.
What are the core rules for constructing legal variable names in Python?
A variable name must start with a letter or an underscore, cannot start with a number, can only contain alphanumeric characters and underscores (A-z, 0-9, and _), is case-sensitive, and cannot be a Python keyword.

Why are the variable names shown in the image considered illegal in Python?
"2myvar" starts with a number, "my-var" contains an illegal hyphen, and "my var" contains an illegal space.
What is the difference between Camel Case and Snake Case variable naming styles?
In Camel Case, each word except the first begins with a capital letter (e.g., myVariableName), while in Snake Case, each word is separated by an underscore (e.g., my_variable_name).

What Python concept is demonstrated in the code snippet shown in the image?
Unpacking a collection, which extracts the elements of a list or tuple into individual variables.
What occurs when the "+" operator is used with strings versus numbers in Python?
With strings, the "+" operator performs concatenation; with numbers, it performs mathematical addition.
Why is separating arguments with commas preferred over the "+" operator when outputting multiple variables in print()?
Commas automatically insert spaces and allow the printing of different data types together without raising a TypeError.
What is the scope behavior when a variable is created inside a function versus outside?
A variable created outside a function is global and accessible anywhere, while a variable created inside a function is local to that function unless declared otherwise.
What is the purpose of the "global" keyword inside a Python function?
It allows a programmer to create a global variable from inside a function or modify the value of an existing global variable within that function.

According to the quiz shown in the image, which option is NOT a legal numeric data type in Python?
"long" is not a legal numeric type in Python (the legal numeric types are int, float, and complex).

What built-in Python function and syntax converts the float variable x=5.5 into an integer?
int(x)

What built-in Python function and syntax converts the integer variable x=5 into a complex number?
complex(x)

What is the output of the code shown in the image: print(int(35.88))?
35 (the int() function removes all decimals without rounding).
How is a complex number written and represented in Python?
Complex numbers are written with a "j" to designate the imaginary part (e.g., 3+5j).
How can a developer generate a random integer between 1 and 9 inclusive in Python?
By importing the built-in random module and calling random.randrange(1, 10).
How does Python represent individual characters given that it lacks a dedicated character data type?
A character is simply represented as a string with a length of 1.
What is the result of applying the slice syntax b[2:5] to the string variable b = "Hello, World!"?
"llo" (characters from index 2 up to, but not including, index 5).
Which membership operators are used to verify whether a phrase or character exists inside a Python string?
"in" and "not in".
Which values are automatically evaluated as False in a Python conditional if statement?
Zero (0), empty strings (""), None, and empty collections.
Why does the string literal "False" evaluate to True in an if statement condition?
Because it is a non-empty string, and all non-empty strings evaluate to True.
How does Python execute a series of chained "elif" statements?
Python evaluates conditions sequentially from top to bottom and executes only the first matching True block, immediately skipping all remaining conditions.
What is the structural role of the "else" keyword in a conditional block?
It acts as a catch-all fallback that executes only when all preceding if and elif conditions evaluate to False, and it must always appear last.