Programming with Python: Fundamentals, Variables, Data Types, and Conditionals

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

1/33

flashcard set

Earn XP

Description and Tags

Comprehensive review flashcards covering programming definitions, Python syntax, error types, variable rules, data types, type casting, string operations, and conditional control structures.

34 Terms

1
New cards

Who created the Python programming language, and in what year was it first released?

Guido van Rossum released Python in 19911991.

2
New cards

What are the four primary application areas for Python listed in the lecture?

Web development (server-side), software development, mathematics, and system scripting.

3
New cards

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.

4
New cards

What are the six core components or operations involved in programming?

Input, output, math, conditional execution, repetition, and algorithms.

5
New cards

What historical origin is cited for the use of the term "bug" to describe engineering difficulties?

It dates back to at least 18891889, when Thomas Edison reported a bug with his phonograph.

6
New cards

What are the three distinct categories of programming errors?

Syntax errors, runtime errors (exceptions), and semantic errors.

7
New cards

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.

8
New cards

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.

9
New cards

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.

10
New cards

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 11 space (with 44 being the most common standard), and all statements within the same block must use the exact same number of spaces.

11
New cards
<p>What error occurs in the provided code snippet, and why?</p>

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.

12
New cards

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.

13
New cards

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.

14
New cards

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, 00-99, and _), is case-sensitive, and cannot be a Python keyword.

15
New cards
<p>Why are the variable names shown in the image considered illegal in Python?</p>

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.

16
New cards

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).

17
New cards
<p>What Python concept is demonstrated in the code snippet shown in the image?</p>

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.

18
New cards

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.

19
New cards

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.

20
New cards

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.

21
New cards

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.

22
New cards
<p>According to the quiz shown in the image, which option is NOT a legal numeric data type in Python?</p>

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).

23
New cards
<p>What built-in Python function and syntax converts the float variable $$x = 5.5$$ into an integer?</p>

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

int(x)

24
New cards
<p>What built-in Python function and syntax converts the integer variable $$x = 5$$ into a complex number?</p>

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

complex(x)

25
New cards
<p>What is the output of the code shown in the image: print(int(35.88))?</p>

What is the output of the code shown in the image: print(int(35.88))?

3535 (the int() function removes all decimals without rounding).

26
New cards

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+5j3+5j).

27
New cards

How can a developer generate a random integer between 11 and 99 inclusive in Python?

By importing the built-in random module and calling random.randrange(11, 1010).

28
New cards

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 11.

29
New cards

What is the result of applying the slice syntax b[2:5] to the string variable b = "Hello, World!"?

"llo" (characters from index 22 up to, but not including, index 55).

30
New cards

Which membership operators are used to verify whether a phrase or character exists inside a Python string?

"in" and "not in".

31
New cards

Which values are automatically evaluated as False in a Python conditional if statement?

Zero (00), empty strings (""), None, and empty collections.

32
New cards

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.

33
New cards

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.

34
New cards

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.