stud
bud
Sign up
Log in
Home
Library
Explore
SAT
More
Introduction to python Flashcards | StudBud
Explore
/
Introduction to python
What is a data type in Python?
What is a runtime error?
Introduction to python
92 terms
·
StudBud Administration
Imported from external platform
Flashcards
92 cards
F
Practice quiz
P
Host live
L
Questions
92
Answers
1
What is a
runtime error
?
An error in the syntax of your code.
Error that occurs while the program is running due to unexpected behavior
An error that is only found during testing.
A pre-compiled error that stops the code from running.
2
What is a data type in Python?
A type of container that holds specific kinds of information.
A tool to debug Python programs.
A category of syntax errors
A built-in function that prints values.
3
Which of the following is NOT true about variable naming rules in Python?
Variable names can include underscores (_).
Variable names cannot contain spaces.
Variable names can start with a number.
Variable names can only contain alphanumeric characters and underscores.
4
What does the with statement do in Python?
Allows you to open a file and ensures it is automatically closed when done
It allows for reading and writing files but does not handle closing them.
It opens a file for writing only.
It automatically appends data to a file without opening it.
5
What is the purpose of the def keyword in Python?
To define a function
To define a class
To define a loop
To define a variable
6
What is the index of the first item in a list?
0
-1
1
It depends on the list.
7
Which operator checks if two values are not equal?
!=
>=
<
==
8
What does the not operator do in Python?
It compares two values.
It checks if two conditions are equal.
It checks if a value is in a list.
It inverts a boolean value (True becomes False, False becomes True).
9
In the code, what is the function __init__ used for?
It is used to define methods inside a class.
It is the constructor that initializes an object with specific attributes.
It is used to define class attributes.
It is used to initialize the object with default values.
10
What is the purpose of nested loops?
To iterate through a single dataset multiple times.
To terminate the loop early.
To create an infinite loop.
To iterate through multiple datasets at once.
11
Why is Python considered beginner-friendly?
It is the oldest programming language
It has only one use case
It has simple English-like syntax
It uses complex syntax
12
What does the elif keyword do in Python?
checks if the previous conditions are false and then runs a new condition.
It checks if the condition before it is true.
It creates a loop that runs multiple times.
It runs a block of code when all other conditions are false.
13
What does the "a" mode do in the open() function?
It reads data from the file but does not write to it.
It opens the file for reading only.
t overwrites the file, keeping only the new content.
It appends new content to the file, preserving existing data.
14
What does the self keyword represent in a class method?
A reference to the current object or instance of the class
The class itself
A global variable
A parameter passed to all methods
15
What does the == operator do in Python?
Checks if one value is less than another.
Checks if one value is greater than another.
Checks if two values are equal.
Assigns a value to a variable.
16
What does the open() function do in Python?
It opens a file for reading and writing.
It creates a new file automatically.
It opens a file for appending and automatically closes it.
It opens a file for writing only.
17
What is a function in Python?
A collection of pre-written code that performs a task
A variable used to store numbers
A data structure used to store values
A loop that repeats an action
18
Which of the following methods can be used to add multiple items at once to a list?
insert()
append()
extend()
pop()
19
What does the super() function do in Python?
Calls a method from the parent class, allowing the child class to reuse it.
It overrides the parent class's methods in the child class.
It overrides the parent class's methods in the child class.
It is used to create a new instance of a class.
20
Which type of error is most likely to occur when expecting numeric input but the user enters text?
ValueError
SyntaxError
TypeError
Runtime error
21
Which function in the random module generates a random integer between two numbers?
random.choice()
random.random()
random.shuffle()
random.randint()
22
What is input validation in programming?
Displaying results to the user
Storing user data for future use
Ensuring the user enters appropriate and expected data
Ensuring the program outputs results correctly
23
What does the int() function do in Python?
It is used for string formatting.
It performs mathematical operations on integers.
It converts a string into an integer.
It converts an integer into a string.
24
What does the % symbol do in Python?
Performs division
Finds the remainder of a division (modulus)
Multiplies two numbers
Represents a percentage
25
Which of these is a valid data type in Python?
String
Boolean
Integer
All of the above
26
What does the else statement do in Python?
It runs a block of code if the if condition is false.
It skips a block of code.
It executes code in a loop.
It prints an error message.
27
What is one benefit of using comments in code?
They help the code execute faster
They make the code easier to understand and debug
They convert Python code into machine language
They automatically fix errors in the code
28
What is a comment in Python?
A command to execute specific instructions
A line of text ignored by Python, used to explain the code
A function to display output
A type of error message
29
What does the or operator do in Python?
It checks for equality between two values.
It returns True if at least one of the conditions is True.
It returns True only if both conditions are True.
It always returns False.
30
What is the effect of the leading underscore (_) in the attributes _name and _house
It makes the attributes public and accessible by anyone.
It marks the attributes as private and should not be accessed directly.
It indicates that the attributes can be modified directly by the user.
It forces the user to input these values when creating the object.
31
What does the raise keyword do in Python?
It pauses the program.
It handles an exception.
It triggers an exception with a custom error message.
It ends the program.
32
What is the purpose of a
unit test
in Python?
To test the overall performance of the program.
To execute the code.
To check if specific part of program (usually a function) works as expected
To compile the code.
33
What is the role of a compiler or interpreter in programming?
It writes the program automatically
It creates hardware for the program to run
It designs the user interface
It turns source code into machine language that the computer understands
34
What does the type() function do in Python?
Checks the length of a variable.
Converts data types into strings.
Changes the value of a variable.
Returns the data type of a variable.
35
What is the role of the cls parameter in a class method?
It refers to the specific instance of the class.
It defines the method for a specific instance of the class.
It is used to set the value of an instance attribute.
It refers to the class itself, allowing access to class-level attributes.
36
What is the term for changing the type of a variable in Python (e.g., from string to integer)?
Casting
Transforming
Changing type
Converting
37
What is the purpose of the print() function in Python?
To display a specified message on the screen
To perform calculations
To install Python libraries
To save a file
38
What does i += 1 mean in Python?
Increase i by 1.
Set i to 1.
Check if i equals 1.
Decrease i by 1.
39
What is the main advantage of using OOP in Python?
It makes your code shorter and faster to execute.
It allows you to only write one function in your program.
Breaks down complex problems into smaller, manageable pieces using classes.
It automatically creates the user interface for your program.
40
Which of the following is a correct way to define a function in Python?
def function_name()
function def name()
def function_name {}
function() def name
41
What is FALSE between a
global
variable and a
local
variable?
A local variable cannot be used outside a function.
A global variable can be used inside a function
Both global and local variables can be used inside and outside a function.
A global variable is created outside a function
42
What is a nested conditional statement in Python?
A conditional statement that checks if a condition is true multiple times.
A statement that compares two conditions using a logical operator.
A conditional statement inside another conditional statement.
A type of loop used to repeat a task.
43
Which of the following lines of code correctly prompts the user to input their name?
input("Enter your name")
name = "Enter your name: "
name = input()
name = input("Enter your name: ")
44
What is the role of parentheses in a function call?
They indicate the return value
They define the function
They store the result of the function
They allow you to pass arguments to the function
45
Which of the following is a comparison operator in Python?
=
-
>=
+
46
What is the purpose of importing a library in Python?
It helps you generate random numbers.
It allows you to use pre-written code and functions in your program.
It automatically fixes errors in your code.
It allows you to write your own functions.
47
What does the function len(students) return in Python?
A random student from the list
The name of the first student in the list
The last student in the list
The total number of students in the list
48
What is the main advantage of inheritance in Python?
It removes the need to define any methods in the child class.
It allows you to create multiple parent classes for a single child class.
It allows you to modify the parent class's methods directly.
It allows you to reuse code and create subclasses with common features.
49
Why do we use end=' ' in the print() statement?
To prevent a newline after the printed text.
To prevent the program from ending.
To clear the console screen.
To add a period at the end of the output.
50
What is the purpose of a loop in programming?
To define a function
To execute code once
To run code conditionally
To repeat code multiple times
51
What does the = operator do in Python?
It multiplies two numbers.
It assigns the value on the right to the variable on the left.
It creates a comment in the code.
It checks for equality between two variables.
52
What does File I/O allow a program to do?
Take a file as input or create a file as output.
Collect user input from a file.
Store information only in memory.
Print information to the screen.
53
Which of these is FALSE about arguments and parameters
Parameters and arguments are same.
Arguments appear when the function is invoked.
Arguments are the actual value
Parameters are like placeholders in the function definition
54
What will happen if multiple elif conditions are true?
Python will execute all the elif blocks that are True.
Python will execute the last elif block.
Python will throw an error.
Python will execute only the first elif block that is True.
55
Why is Python in high demand?
It's hard to learn and rare
It only works for small projects
It's used by major companies and supports diverse applications
It is a new language
56
What is Object-Oriented Programming (OOP)?
Organizing code using objects and classes to model real-world concepts
A programming paradigm focused on writing code step-by-step.
A programming style that only uses functions and loops.
A technique used to write complex programs quickly without planning.
57
What does the break keyword do in a loop?
It starts the loop over from the beginning
It pauses the loop until a condition is met
It skips the current iteration and goes to the next one
It stops the loop and exits the loop immediately
58
How do you concatenate strings in Python?
Using the - symbol
Using the * symbol
Using the + symbol
Using the / symbol
59
What does the and operator do in Python?
It returns True if at least one condition is True.
It returns True only if both conditions are True.
It checks if both values are equal.
It checks if two values are different.
60
What is the correct way to convert user input into integers in Python?
input("What's x? ").cast()
int("What's x? ")
int(input("What's x? "))
input("What's x? ").toInt()
61
What is a dictionary in Python?
A data structure that stores items in a list
A data structure that stores items in key-value pairs
A data structure used for storing boolean values
A built-in function to sort lists
62
What happens if the code inside a function is not indented properly in Python?
The function will run without errors
The function will be skipped
Python will throw an error because indentation is required
The function will execute but with incorrect results
63
What is the benefit of using a tuple over a list for storing values?
Tuples use more memory than lists.
Tuples help protect the integrity of the data by being immutable.
Tuples are mutable, so they can be changed later.
Tuples can store only strings, while lists can store other data types.
64
Which of the following code snippets will correctly remove whitespace from the user's input in Python?
name = name.strip()
name = name.clean()
name = name.trim()
name = name.remove_whitespace()
65
What is computer programming?
Writing instructions for computers to perform tasks
Designing hardware for computers
Typing random words on a keyboard
Using computers to play games
66
What does the if statement do in Python?
It executes a block of code only if a specific condition is true.
It defines a new function.
It executes a block of code regardless of any condition.
It repeats a block of code a certain number of times.
67
What happens if you put a # at the beginning of a line in Python?
It causes a syntax error
It makes the line bold when printed
The line becomes a comment and is ignored by the Python interpreter
The program stops running
68
What is the primary purpose of a @classmethod in Python?
Allows a method to be called on class itself, not on the class instance.
It allows a method to access private class attributes.
It allows a method to modify the attributes of an instance.
It is used to initialize class instances.
69
What is the purpose of the try block in Python?
To test a block of code for errors before they occur.
To allow code to run even if an error occurs.
To handle errors after they occur.
To define a function that can handle multiple exceptions.
70
Which character is used to write a comment in Python?
//
%
/
#
71
What will happen if you use the append method on a list?
It replaces the last item in the list.
It removes the last item from the list.
It adds a new item at the end of the list.
It adds a new item at the beginning of the list.
72
What does the += operator do in Python?
It checks if two values are equal.
It assigns a constant value to a variable.
It increases the value of a variable by a specified amount.
It assigns a new value to a variable.
73
What is the difference between == and = in Python?
Both are used for assignment
== is used to compare values, while = is used to assign a value
There is no difference
== is used to assign a value, while = is used to compare values
74
What is a
Syntax Error
in Python?
An error that occurs when you try to use a function that does not exist.
Error that occurs due to a mistake in the code's structure or formatting.
An error that occurs when the program tries to divide by zero.
An error that occurs when you try to use an undefined variable.
75
Why does the # inside a string (e.g., print("Hi # there.")) not act as a comment?
Because it's treated as part of the string text
Because the # must be at the start of the line
Because Python ignores all strings
Because it's a syntax error
76
Which data structure provides key-value pairs in Python?
Set
Tuple
List
Dictionary
77
What does the f in f"So, you're {age} years old." signify?
It flags an error in the code.
It formats the text as uppercase.
It forces the variable to become a string.
It allows variables to be inserted directly into the string.
78
What does PEMDAS stand for?
Print, Execute, Multiply, Divide, Add, Subtract
Parentheses, Evaluation, Math, Divide, Average, Subtract
Programming Execution, Math, Division, Addition, Subtraction
Parentheses, Exponents, Multiplication, Division, Addition, Subtraction
79
What does the input() function do in Python?
Adds two numbers together.
Prints text to the console.
Accepts input from the user.
Ends a Python program.
80
What does .title() do to a string in Python?
Removes leading and trailing spaces.
Capitalizes the first letter of each word in the string.
Capitalizes only the first letter of the string.
Converts all characters to uppercase.
81
Which of the following lines of code will display the message "Hello World!" on the screen?
output("Hello World!")
echo("Hello World!")
print("Hello World!")
display("Hello World!")
82
Which of the following functions is used to calculate the average of a set of numbers in Python's statistics library?
variance()
median()
mode()
mean()
83
How do you print both the key and value in a dictionary?
for student, students[student] in students:
for key, value in students:
for student, house in students:
for student in students: print(student, students[student])
84
What is the purpose of passing parameters to a function?
To modify the function’s name
To provide data that the function will use in its operation
To change the function’s return type
To make the function optional
85
What is a Boolean in Python?
A data type that represents numbers.
A data type that represents text.
A data type that represents True or False values.
A data type that represents decimal numbers.
86
What is the purpose of using f before a string like this: f"hello, {name}"?
It makes the string bold.
It creates a formatted number.
It tells Python to add extra spaces.
It formats the string and allows variable substitution inside the string.
87
What type of numbers do the float() function convert to?
Integers
Strings
Booleans
Real numbers (numbers with decimal points)
88
What is the function of the continue keyword in a loop?
To start the loop over from the beginning
To stop the loop and exit
To skip the current iteration and continue with the next iteration
To repeat the current iteration of the loop
89
What is another name for the # character in Python?
Octothorpe or pound character
Asterisk
Ampersand
Slash
90
What is the purpose of the return statement in a function?
To pass data back to the caller of the function
To stop the function
To print the function's output
To create new variables
91
What does the else block do in Python multiple conditionals?
It runs a block of code if the elif condition is True.
It runs a block of code if all previous conditions are False.
It checks whether the previous conditions are True.
It runs a block of code if the if condition is True
92
Why can’t a variable name start with a number in Python?
Variable names can start with numbers.
Numbers in variable names are considered operators.
It will cause a syntax error.
Python reserves numbers for calculations only.