stud
bud
Sign up
Log in
Home
Library
Explore
SAT
More
Python Programming Basics Flashcards | StudBud
Explore
/
Python Programming Basics
Python Programming Basics
35 terms
·
StudBud Administration
·
20 plays
Test your knowledge on fundamental concepts and syntax in Python programming
Flashcards
35 cards
F
Practice quiz
P
Host live
L
Questions
35
Answers
1
What does 'yield' return in a function?
A list
A string
A generator
A tuple
2
What does __init__.py signify?
A script file
A package directory
A data file
A regular file
3
True or false: you can create custom context managers?
False
True
4
True or false: 'with' keyword is used for context managers?
False
True
5
Which statement is true about context managers?
They handle exceptions
They simplify resource management
They manage memory
They optimize performance
6
What does 'with' do in file handling?
Closes the file
Reads the file
Writes to the file
Opens the file
7
Which is a benefit of using context managers?
Less code
Slower execution
More complexity
More errors
8
True or false: context managers are only for files?
True
False
9
True or false: 'read()' reads the entire file.
True
False
10
True or false: context managers can be nested?
True
False
11
True or false: __init__.py is mandatory?
False
True
12
What does 'with open() as f' do?
Reads file content
Closes file immediately
Creates a file
Opens file safely
13
What does 'init' do in a class?
Creates instances
Defines methods
Handles exceptions
Initializes attributes
14
True or false: context managers can be used with any object?
False
True
15
What is a common use of __init__.py?
To import modules
To define variables
To create classes
To write functions
16
True or false: 'list()' converts iterable to list.
False
True
17
True or false: context managers can manage files?
False
True
18
What does 'append' do in a list?
Adds an item
Sorts the list
Removes an item
Clears the list
19
What does 'class' define in Python?
An object
A module
A blueprint
A function
20
True or false: 'next()' retrieves the next item.
True
False
21
Which file mode is for appending?
w
r
a
x
22
True or false: 'strip()' removes whitespace.
True
False
23
Which method is called first in a class?
next()
__init__()
__repr__()
__str__()
24
True or false: context managers can prevent resource leaks?
True
False
25
Which method is called on exit?
__leave__
__finish__
__close__
__exit__
26
What does 'self' refer to in a class?
The class itself
The function
The instance
The method
27
Which method reads a line from a file?
write()
readlines()
read()
readline()
28
Which method is used to read all lines?
write()
readline()
read()
readlines()
29
Which method is used to write to a file?
write()
close()
read()
append()
30
What is the main advantage of __init__.py?
Defines package structure
Reduces code size
Improves readability
Increases performance
31
Which keyword is used to define a class?
function
def
class
method
32
What is the purpose of __enter__ method?
To close resources
To handle errors
To exit context
To initialize context
33
True or false: 'open()' can create files.
False
True
34
Which of these is a context manager?
type() function
open() function
len() function
print() function
35
True or false: 'yield' creates a generator.
True
False