What is one of the key characteristics of Python related to its programming paradigm?
Python is Object-Oriented and supports concepts such as polymorphism, operator overloading, and multiple inheritance.
How does Python identify blocks of code?
Python uses indentation to identify blocks of code.
1/307
p.1
Characteristics of Python

What is one of the key characteristics of Python related to its programming paradigm?

Python is Object-Oriented and supports concepts such as polymorphism, operator overloading, and multiple inheritance.

p.1
Characteristics of Python

How does Python identify blocks of code?

Python uses indentation to identify blocks of code.

p.25
Lists and List Operations

What is the output of list1[1:2:4]?

[2]

p.25
Lists and List Operations

What does list1[1:8:2] return?

[2, 4, 6, 8]

p.14
Control Structures in Python

What is iteration in programming?

Iteration is the repeated execution of a set of statements using loops as long as the condition is true.

p.9
Error Handling and Exceptions

How can users define custom exceptions in Python?

Users can define custom exceptions by creating a new class that is derived from the Exception class.

p.17
Dictionaries and Dictionary Comprehensions

What is printed when iterating over the values of the dictionary 'college'?

Values are: block1, block2, block3

p.19
Control Structures in Python

What is the purpose of the 'pass' statement in Python?

'pass' is a null statement used as a placeholder for functionality to be added later; it is not ignored by the interpreter.

p.28
Dictionaries and Dictionary Comprehensions

What is the output of the dictionary dict1 = {'brand':'mrcet', 'model':'college', 'year':2004}?

The output is {'brand': 'mrcet', 'model': 'college', 'year': 2004}.

p.7
Functions and Modules

What symbol is used for single-line comments in Python?

#

p.4
Variables and Memory Management

Can you change the type of a variable after initialization in Python?

Yes, you can change the type of a variable after initialization, for example, x = 5 (int) and then x = 'kve' (str).

p.13
Control Structures in Python

What is the syntax structure of if-elif-else in Python?

If <test expression>: Body of if statements elif <test expression>: Body of elif statements else: Body of else statements

p.31
Variables and Memory Management

Which of the following is not a keyword?

a) Eval

p.4
Variables and Memory Management

What does Python allow regarding multiple assignments?

Python allows you to assign a single value to several variables simultaneously, such as a = b = c = 1.

p.7
Control Structures in Python

What is the output of e = a + (b * c) / d when a=20, b=10, c=15, d=5?

50.0

p.19
Strings and String Operations

How is a string defined in Python?

A string is a sequence of characters enclosed within quotes, and every string object is of the type 'str'.

p.4
Variables and Memory Management

How does Python output variables?

Python uses the print statement to output variables, and variables do not need to be declared with any particular type.

p.12
Control Structures in Python

What will be the output if the input number is 2 in the if-else example?

The output will be 'a is smaller than the input given'.

p.27
Tuples and Their Properties

What is the result of a tuple comprehension?

It produces a generator object, not a tuple.

p.12
Control Structures in Python

What is the purpose of the elif statement in Python?

The elif statement allows checking multiple expressions for TRUE and executing a block of code as soon as one condition is true.

p.20
Strings and String Operations

What does the expression str * 2 do?

It prints the string two times.

p.15
Control Structures in Python

What is the output of the following code: i=1 while i<=6: print('KV School') i=i+1?

KV School KV School KV School KV School KV School KV School

p.28
Dictionaries and Dictionary Comprehensions

What is a set comprehension in Python?

A set comprehension is a concise way to create a set using a single line of code, similar to list comprehensions, and is enclosed within curly brackets.

p.6
Control Structures in Python

What are the two basic types of statements in Python?

The assignment statement and the print statement.

p.4
Variables and Memory Management

How can you assign multiple objects to multiple variables in Python?

You can assign multiple objects to multiple variables using syntax like a, b, c = 1, 2, 'kvsch'.

p.7
Functions and Modules

How does Python handle comments in the code?

Comments are discarded by the Python interpreter and can be single-line (starting with #) or multi-line (using triple quotes).

p.27
Tuples and Their Properties

How do you find the number of items in a tuple?

You use the len() function.

p.20
Strings and String Operations

How do you print the first character of a string in Python?

You can print the first character using str[0].

p.20
Strings and String Operations

What does the syntax [Start: stop: steps] represent in string slicing?

It represents the starting index, stopping index, and step size for slicing a string.

p.20
Strings and String Operations

What will the expression str[2:5] return if str = 'Hello World!'?

It will return the characters starting from the 3rd to the 5th character, which is 'llo'.

p.27
Tuples and Their Properties

How do you create a list of 2-tuples like (number, square)?

You can use a list comprehension, for example: [(x, x**2) for x in range(6)].

p.20
Strings and String Operations

How do you concatenate a string with another string in Python?

You can concatenate using the + operator, e.g., str + 'TEST'.

p.20
Strings and String Operations

What is the output of print(str[2:]) if str = 'Hello World!'?

It prints the string starting from the 3rd character, which is 'llo World!'.

p.15
Control Structures in Python

What is the syntax for a while loop in Python?

while(expression): Statement(s)

p.18
Control Structures in Python

What is the syntax for a nested for loop?

The syntax is: for val in sequence1: for val in sequence2: statements.

p.28
Dictionaries and Dictionary Comprehensions

What is the output of the set comprehension a = {x for x in 'abracadabra' if x not in 'abc'}?

The output is {'r', 'd'}.

p.9
Functions and Modules

How do you import a module in Python?

You can import a module using the syntax: import <module-name>.

p.6
Control Structures in Python

What is the purpose of the input() function in Python?

It receives input from the user through the keyboard.

p.11
Control Structures in Python

What is the output of the following code: a = 3; if a > 2: print(a, 'is greater'); print('done')?

3 is greater done

p.1
Characteristics of Python

Is Python an open source programming language?

Yes, Python is an open source programming language that can be freely downloaded and installed.

p.8
Error Handling and Exceptions

What does a ZeroDivisionError indicate in Python?

A ZeroDivisionError indicates that the second argument used in a division or modulo operation was zero.

p.8
Error Handling and Exceptions

What does an OverflowError signify in Python?

An OverflowError signifies that an arithmetic operation has exceeded the limits of the current Python runtime, typically due to excessively large float values.

p.8
Error Handling and Exceptions

When is an ImportError raised in Python?

An ImportError is raised when trying to import a module that does not exist, often due to a typo in the module name.

p.11
Control Structures in Python

What is the syntax of an if-else statement?

if test expression: Body of if statements else: Body of else

p.1
Characteristics of Python

What feature allows users to interact directly with Python while writing programs?

Python is an interactive programming language, allowing users to interact with the interpreter directly.

p.21
Strings and String Operations

What is the output of x[::-2] for the string 'computer'?

'rtpo'

p.33
Control Structures in Python

What does the letter 'd' do in a sequence?

It generates numbers up to a specified value.

p.18
Strings and String Operations

How do you iterate over a string in Python?

You can iterate over a string using a for loop, like this: for name in college: print(name).

p.13
Control Structures in Python

What will be the output if the inputs are 5, 2, and 9 in the if-elif-else example?

a is greater

p.37
Lists and List Operations

What is the output of the code 'list1=[] for x in range(10): list1.append(x**2)'?

The output is [0, 1, 4, 9, 16, 25, 36, 49, 64, 81].

p.20
Strings and String Operations

What is the purpose of the index in string operations?

The index indicates which character in the sequence we want to select.

p.4
Variables and Memory Management

What happens when you execute a, b, c = 5, 10, 20 in Python?

This creates three variables named a, b, c and initializes them with values 5, 10, and 20 respectively.

p.20
Strings and String Operations

What is the default value of 'start' in string slicing?

The default value of 'start' is 0.

p.27
Tuples and Their Properties

What is the output of len((1,2,3,4,5,6,2,10,2,11,12,2))?

The output is 12.

p.6
Control Structures in Python

What is the result of the expression 3 + 4 * 2?

The result is 11 because multiplication is evaluated before addition.

p.27
Tuples and Their Properties

Can you iterate over a generator object multiple times?

No, you can only iterate over it once.

p.34
Control Structures in Python

What is the output of the following code? A = 0 while A<10: print(A, ' , ') A = A+1 print('\n', A)

0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10

p.34
Error Handling and Exceptions

What is the output of the following code? T = (5) T = T*2 print(T)

TypeError: 'int' object is not subscriptable

p.3
Python Data Types

What are the standard numeric types in Python?

int, float, complex

p.1
Characteristics of Python

What is notable about Python's syntax?

Python's syntax is simple and straightforward, contributing to its popularity.

p.8
Error Handling and Exceptions

What are syntax errors in Python?

Syntax errors are basic errors that arise when the Python parser cannot understand a line of code, and they are almost always fatal.

p.23
Lists and List Operations

What are the characteristics of list items in Python?

List items are ordered, changeable, and can be repeated.

p.8
Error Handling and Exceptions

When does a KeyError occur in Python?

A KeyError occurs when a dictionary object is accessed with a key that does not exist in the dictionary.

p.14
Control Structures in Python

What is the output of the given code when var is set to 100?

3 - Got a true expression value 100

p.17
Dictionaries and Dictionary Comprehensions

What does the dictionary 'college' contain?

ces: block1, it: block2, ece: block3

p.31
Control Structures in Python

What is the order of precedence in python?

a) i,ii,iii,iv,v,vi

p.37
Dictionaries and Dictionary Comprehensions

What does the statement 'StudentDict = dict()' do?

It initializes an empty dictionary named StudentDict.

p.20
Strings and String Operations

What is a slice in the context of strings?

A slice is a segment or part of a string that can be selected using the slice operator.

p.6
Control Structures in Python

How does operator precedence affect expression evaluation in Python?

Operator precedence determines the order in which operators are evaluated in an expression.

p.11
Control Structures in Python

What will be printed when a = -1 and the condition if a < 0 is true?

-1 a is smaller Finish

p.11
Control Structures in Python

What is the output of the code: a = 10; if a > 9: print('A is Greater than 9')?

A is Greater than 9

p.11
Control Structures in Python

What does an else statement do in an if-else structure?

It contains the block of code that executes if the conditional expression in the if statement resolves to false.

p.11
Control Structures in Python

What is the maximum number of else statements that can follow an if statement?

At most only one else statement.

p.8
Error Handling and Exceptions

What triggers an IndexError in Python?

An IndexError is triggered when you refer to a sequence that is out of range, such as accessing an index that does not exist in a list.

p.35
Variables and Memory Management

What will be printed if y is 10?

10

p.8
Error Handling and Exceptions

What is an IndentationError in Python?

An IndentationError occurs when there is an unexpected indent or inconsistent indentation in the code.

p.29
Dictionaries and Dictionary Comprehensions

What is the purpose of the copy() method in a dictionary?

It returns a shallow copy of the dictionary.

p.33
Control Structures in Python

What is the output of the following code: Sum = 0 for k in range(5): Sum = Sum+k print(Sum)?

The output is 10.

p.33
Control Structures in Python

What is the output of the following code: Sum = 0 for k in range(10, 1, -2): Sum = Sum+k print(Sum)?

The output is 30.

p.21
Strings and String Operations

What does it mean that strings are immutable?

We can’t change an existing string; we can only create a new variation.

p.25
Tuples and Their Properties

What are the characteristics of tuples in Python?

Supports all operations for sequences, is immutable, but member objects may be mutable.

p.13
Control Structures in Python

What is an example of using if-elif-else to compare three numbers?

a=int(input('enter the number')) b=int(input('enter the number')) c=int(input('enter the number')) if a>b: print('a is greater') elif b>c: print('b is greater') else: print('c is greater')

p.18
Control Structures in Python

What is the output of the nested for loop example provided?

The output is: 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5.

p.28
Dictionaries and Dictionary Comprehensions

How are dictionaries created in Python?

Dictionaries are created using curly brackets and consist of key-value pairs.

p.26
Tuples and Their Properties

How can you create an empty tuple in Python?

You can create an empty tuple using X = ().

p.31
Control Structures in Python

What will be the value of X in the following Python expression? X = 2+9*((3*12)-8)/10

b) 30.8

p.26
Tuples and Their Properties

How do you access the first and last elements of a tuple?

The first element can be accessed with T[0] and the last element with T[-1].

p.16
Control Structures in Python

What is the purpose of a for loop in Python?

A for loop is used for repeated execution of a group of statements for a desired number of times, iterating over items of lists, tuples, strings, dictionaries, and other iterable objects.

p.16
Control Structures in Python

What is the syntax of a for loop in Python?

The syntax is: for <loopvariable> in <sequence>: Statement(s)

p.16
Control Structures in Python

What does the loop variable hold during each iteration of a for loop?

During each iteration, the loop variable holds a value from the sequence.

p.30
Lists and List Operations

What is a list comprehension?

A way to create a new list using an existing sequence.

p.10
Control Structures in Python

What does the sys.version_info function return?

It returns the version information of Python, including major, minor, micro, release level, and serial.

p.30
Control Structures in Python

What is the purpose of a 'for' loop in Python?

To iterate over a sequence when the number of repetitions is known.

p.16
Control Structures in Python

In the example 'list = ['K','V','S','C','H']; i = 1; for item in list:', what is being iterated over?

The loop iterates over the items in the list ['K','V','S','C','H'].

p.22
Strings and String Operations

What does the isdigit() method check for?

Returns true if the string contains only digits; false otherwise.

p.36
Dictionaries and Dictionary Comprehensions

How do you enter n number of students' data in a loop in Python?

for i in range(n): rollno = input('Enter Roll No:'); name = input('Enter Name:'); physicsMarks = int(input('Enter Physics Marks:')); chemistryMarks = int(input('Enter Chemistry Marks:')); mathMarks = int(input('Enter Maths Marks:')); studentDict[rollno] = {'name': name, 'physics': physicsMarks, 'chemistry': chemistryMarks, 'math': mathMarks}

p.15
Control Structures in Python

What does the following code output: i=1 while i<=3: print('KV School',end=' ') j=1 while j<=1: print('CS DEPT',end='') j=j+1 i=i+1 print()?

KV School KV School KV School CS DEPT

p.17
Dictionaries and Dictionary Comprehensions

What is printed when iterating over the keys of the dictionary 'college'?

Keys are: ces, it, ece

p.19
Control Structures in Python

How does the 'continue' statement function in a loop?

The 'continue' statement skips the current iteration and continues with the next iteration of the loop.

p.31
Functions and Modules

Find the output of the function example(a) where a = 'hello'.

b) cannot perform mathematical operation on strings

p.26
Tuples and Their Properties

What is the syntax to access an element in a tuple?

The syntax is <Name of the tuple>[index].

p.2
Variables and Memory Management

What are tokens in Python?

Tokens are the smallest identifiable units in Python, including keywords, identifiers, literals, operators, and delimiters.

p.30
Dictionaries and Dictionary Comprehensions

What types of data can be stored in a dictionary?

Any type, but keys must be of an immutable type.

p.5
Control Structures in Python

What operator is used for integer division in Python?

The operator for integer division is /.

p.5
Control Structures in Python

What is the token for the remainder operation in Python?

The token for the remainder operation is %.

p.5
Control Structures in Python

What does the binary left shift operator do in Python?

The binary left shift operator is represented by << and shifts the bits of a number to the left.

p.30
Control Structures in Python

What types of loops are available in Python?

While loop and for loop.

p.16
Control Structures in Python

What is the output of this code: for k in range(1, 10): if k % 2 == 0: print(k, end=', ')?

The output is: 2, 4, 6, 8

p.22
Strings and String Operations

What is the purpose of the isalpha() method?

Returns true if the string has at least 1 character and all characters are alphabetic; false otherwise.

p.36
Dictionaries and Dictionary Comprehensions

What is the first step to create a dictionary to store student details in Python?

studentDict = {}

p.24
Lists and List Operations

What does the expression ['Hi!'] * 4 return?

['Hi!', 'Hi!', 'Hi!', 'Hi!']

p.24
Lists and List Operations

What does the expression 3 in [1, 2, 3] evaluate to?

True

p.29
Dictionaries and Dictionary Comprehensions

What does the keys() method return?

It returns a new view of the dictionary's keys.

p.34
Tuples and Their Properties

What is the output of the following code? x=[4,5,66,9] y=tuple(x)

(4, 5, 66, 9)

p.29
Dictionaries and Dictionary Comprehensions

What is the purpose of the setdefault(key[,d]) method?

If key is in the dictionary, it returns its value. If not, it inserts key with a value of d and returns d (defaults to None).

p.14
Control Structures in Python

What are the three types of loop statements in Python?

While Loop, For Loop, Nested For Loops

p.19
Control Structures in Python

What does the 'break' statement do in Python?

The 'break' statement terminates the loop containing it and control flows to the statement immediately after the body of the loop.

p.26
Tuples and Their Properties

What are tuples and how do they compare to lists in terms of efficiency?

Tuples are more efficient than lists due to Python's implementation.

p.8
Error Handling and Exceptions

What type of error occurs when Python encounters a syntax issue in the code?

A syntax error or parsing error occurs when the proper structure of the language is not followed.

p.21
Strings and String Operations

What does x[3:] return for the string 'computer'?

'puter'

p.21
Strings and String Operations

What is the output of x[:5] for the string 'computer'?

'compu'

p.21
Strings and String Operations

What does x[-1] return for the string 'computer'?

'r'

p.21
Strings and String Operations

What is the result of x[-3:] for the string 'computer'?

'ter'

p.8
Error Handling and Exceptions

What causes a TypeError in Python?

A TypeError occurs when two unrelated types of objects are combined, such as adding an integer and a string.

p.33
Control Structures in Python

What does the letter 'c' indicate in a sequence?

It indicates the difference between every two consecutive numbers in the sequence.

p.23
Lists and List Operations

What are lists in Python used for?

Lists are used to store different types of items in a variable, allowing for the collection of data.

p.30
Strings and String Operations

What are docstrings in Python?

Strings enclosed within triple quotes that can span multiple lines.

p.33
Control Structures in Python

What is the output of the following code: for k in range(4): for j in range(k): print('*', end=' ')?

The output is: * * * * *

p.34
Lists and List Operations

Write python code to sort the list, L, in descending order.

L.sort(reverse=True)

p.22
Strings and String Operations

What does the isupper() method do?

Returns true if the string has at least one cased character and all cased characters are in uppercase; false otherwise.

p.24
Lists and List Operations

What does L[1:] return if L = ['kvsch', 'school', 'KVSCH!']?

['school', 'KVSCH!']

p.23
Lists and List Operations

What does the pop() method do?

The pop() method removes the element at the specified position.

p.23
Lists and List Operations

How can you create a list in Python?

You can create a list using square brackets, e.g., list1=[1,2,3,'A','B',7,8,[10,11]].

p.32
Lists and List Operations

If l=[11,22,33,44], then output of print(len(l)) will be?

a) 4

p.18
Control Structures in Python

What is a nested for loop?

A nested for loop is when one loop is defined within another loop.

p.37
Lists and List Operations

How do you search for an item in a list in Python?

You can iterate through the list and compare each element to the item being searched for.

p.14
Control Structures in Python

What type of expression does a while loop contain?

A Boolean expression.

p.28
Dictionaries and Dictionary Comprehensions

What are the characteristics of keys in a Python dictionary?

Keys must be unique and of immutable types.

p.5
Control Structures in Python

What are some examples of expressions in Python?

Examples include simple expressions like a value by itself or a variable, and more complex expressions like z=x+20.

p.30
Dictionaries and Dictionary Comprehensions

What is the output of the dictionary comprehension z={x: x**2 for x in (2,4,6)}?

{2: 4, 4: 16, 6: 36}

p.7
Functions and Modules

What are the symbols used for multi-line comments in Python?

Triple double quotes (""" ) or triple single quotes (''' )

p.4
Variables and Memory Management

How do you combine text and a variable in Python?

You can combine text and a variable using the '+' character, for example, print('Python is ' + x).

p.25
Lists and List Operations

What is the output of list1[2:5] if list1 is [1, 2, 3, 4, 5, 6, 7, 8]?

[3, 4, 5]

p.25
Lists and List Operations

What does list1[:6] return if list1 is [1, 2, 3, 4, 5, 6, 7, 8]?

[1, 2, 3, 4, 5, 6]

p.36
Dictionaries and Dictionary Comprehensions

What is the Python code to create and add items to a dictionary based on user input?

D = {} while True: K = input('type a key'); V = int(input('type the value')); D[K] = V; C = input('type 'y' to add more')

p.36
Control Structures in Python

How can you check if a given item is present in a list using a for loop?

for item in list: if item == given_item: print('Item found')

p.24
Lists and List Operations

What does the expression len([1, 2, 3]) return?

3

p.25
Lists and List Operations

What is the output of the list comprehension: list1=[x**2 for x in range(10)]?

[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

p.3
Python Data Types

What are sequences in Python?

An ordered collection of elements, including Strings, Lists, and Tuples.

p.3
Python Data Types

What is a set in Python?

An unordered collection of any type without duplicate entries.

p.22
Strings and String Operations

What does the isspace() method return?

Returns true if the string contains only whitespace characters; false otherwise.

p.23
Lists and List Operations

What is the purpose of the clear() method in a list?

The clear() method removes all the elements from the list.

p.24
Lists and List Operations

What does L[-2] return if L = ['kvsch', 'school', 'KVSCH!']?

'school'

p.22
Strings and String Operations

What does the count() method return?

Returns the occurrence of a substring in another string.

p.9
Error Handling and Exceptions

What does a ValueError in Python indicate?

A ValueError indicates a problem with the content of the object you tried to assign a value to.

p.14
Control Structures in Python

What does a while loop do in Python?

A while loop keeps iterating a block of code until the desired condition is met.

p.5
Control Structures in Python

What is an expression in Python?

An expression is a combination of values, variables, and operators that is evaluated using an assignment operator.

p.9
Functions and Modules

What command can you use in Python to get help on modules?

You can use the help() command followed by the name of any module, keyword, or topic.

p.21
Strings and String Operations

What does the slice x[1:4] return for the string 'computer'?

'omp'

p.31
Functions and Modules

Select all options that print. hello-how-are-you

Options that use print() function with the string.

p.2
Variables and Memory Management

What are keywords in Python?

Keywords are reserved words that have special meanings, such as int, print, input, for, and while.

p.2
Variables and Memory Management

What are the rules for naming identifiers in Python?

Identifiers cannot use keywords or operators, must start with an alphabet or underscore, cannot contain spaces, cannot start with a number, and are case sensitive.

p.2
Variables and Memory Management

What is a variable in Python?

A variable is used to store data and is an object in Python, representing a reserved memory location to store values.

p.16
Control Structures in Python

What is the output of the following code: L = [1, 2, 3, 4, 5]; for var in L: print(var, end=' ')?

The output is: 1 2 3 4 5

p.33
Control Structures in Python

What does the letter 'b' indicate in a sequence?

It indicates the end of the sequence.

p.29
Dictionaries and Dictionary Comprehensions

What does the clear() method do in a dictionary?

It removes all items from the dictionary.

p.30
Variables and Memory Management

What are examples of immutable types?

int, float, string, tuple.

p.10
Control Structures in Python

What is sequential execution?

It means executing the statements one by one starting from the first instruction onwards.

p.22
Strings and String Operations

What does the islower() method determine?

Returns true if the string has at least 1 cased character and all cased characters are in lowercase; false otherwise.

p.10
Control Structures in Python

What is the syntax of an if statement in Python?

if <expression>: statement(s)

p.33
Control Structures in Python

What is the output of the following code: for k in range(5, 0, -1): for j in range(k): print('*', end=' ')?

The output is: * * * * * * * * * * * * * * *

p.3
Variables and Memory Management

How does Python handle variable declaration?

Python variables do not need explicit declaration; memory is reserved automatically upon assignment.

p.23
Lists and List Operations

What does the count() method do in a list?

The count() method returns the number of elements with the specified value.

p.35
Lists and List Operations

What are the items in the list if the output is ['b', 'c', 'd']?

['b', 'c', 'd']

p.23
Lists and List Operations

What is the function of the insert() method in a list?

The insert() method adds an element at the specified position.

p.32
Strings and String Operations

What will be the output of print('hello' + '-' + 'how' + '-' + 'are' + 'you')?

hello-how-areyou

p.37
Control Structures in Python

What does the code 'if C!=’y’: break' do?

It breaks out of a loop if the variable C is not equal to 'y'.

p.7
Control Structures in Python

What is the result of (10+10)*2?

40

p.31
Error Handling and Exceptions

What error occurs when you execute the following Python code snippet? apple = mango

b) NameError

p.37
Dictionaries and Dictionary Comprehensions

What is the purpose of 'studentDict[rollno]=[name, physicsMarks, chemistryMarks, mathMarks]'?

It assigns a list of student details to a key 'rollno' in the dictionary studentDict.

p.9
Functions and Modules

What is the output of print(sys.version) in Python?

It outputs the version of Python currently being used, such as '3.8.0'.

p.21
Strings and String Operations

What is the result of the slice x[1:6:2] for the string 'computer'?

'opt'

p.26
Tuples and Their Properties

Can you modify the elements of a tuple after it is created?

No, tuples are immutable and cannot be modified after creation.

p.26
Tuples and Their Properties

What error is raised if you try to modify a tuple?

A TypeError is raised if you try to modify a tuple.

p.26
Tuples and Their Properties

What does the count() function do when used with tuples?

The count() function returns the number of times a specified value occurs in a tuple.

p.26
Tuples and Their Properties

How do you find the index of a specified value in a tuple?

You can use the index() function to find the position of a specified value in a tuple.

p.21
Strings and String Operations

What does x[:-2] return for the string 'computer'?

'comput'

p.10
Control Structures in Python

What does the calendar.isleap function determine?

It determines whether a given year is a leap year or not.

p.10
Control Structures in Python

What are the three types of flow of execution in Python?

1. Sequential execution 2. Selection/Conditional statements 3. Iterations/loop

p.30
Strings and String Operations

What is a string in Python?

A sequence of characters, enclosed in single or double quotes.

p.10
Control Structures in Python

What is the purpose of selection or conditional statements?

They help execute statements based on whether a condition is evaluated to True or False.

p.29
Dictionaries and Dictionary Comprehensions

What is the function of the items() method in a dictionary?

It returns a new view of the dictionary's items (key, value).

p.35
Variables and Memory Management

What is the value of T if T is an integer and equals 10?

10

p.24
Lists and List Operations

What does L[2] return if L = ['kvsch', 'school', 'KVSCH!']?

'KVSCH'

p.3
Variables and Memory Management

Provide an example of assigning an integer to a variable in Python.

a = 100

p.23
Lists and List Operations

What is the purpose of the reverse() method?

The reverse() method reverses the order of the list.

p.32
Strings and String Operations

Which point can be considered as difference between string and list?

b. Mutability

p.17
Tuples and Their Properties

What are the first four prime numbers printed from the tuple?

2, 3, 5, 7

p.6
Control Structures in Python

What is the purpose of a statement in Python?

A statement is an instruction that the Python interpreter can execute.

p.7
Control Structures in Python

What does the expression e = (a + b) * c / d evaluate to when a=20, b=10, c=15, d=5?

90.0

p.5
Control Structures in Python

What does the assignment operator do in Python?

The assignment operator assigns a value to a variable and evaluates expressions.

p.2
Variables and Memory Management

What is the character set recognized by Python?

The character set includes letters (A-Z, a-z), digits (0-9), special symbols (+, -, /, %, **, *, [], {}, #, $), white spaces (blank space, tabs, carriage return, newline, form feed), and all ASCII and UNICODE characters.

p.5
Control Structures in Python

What types of operators does Python support?

Python supports Arithmetic Operators, Relational Operators, Logical Operators, and more.

p.5
Control Structures in Python

What is the token for addition in Python?

The token for addition is +.

p.30
Control Structures in Python

What are the three programming constructs supported by Python?

Sequence, Selection, and Iteration.

p.30
Variables and Memory Management

What is the difference between mutable and immutable types?

Immutable types cannot be modified, while mutable types can be modified.

p.36
Lists and List Operations

How do you create a list of odd numbers within a given range m and n in Python?

L = [x for x in range(m, n + 1) if x % 2 != 0]

p.16
Control Structures in Python

What does the following code output: for k in range(10): print(k, end=', ')?

The output is: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

p.22
Strings and String Operations

What does the isalnum() method do?

Returns true if the string has at least 1 character and all characters are alphanumeric; false otherwise.

p.36
Lists and List Operations

How do you create a list of squares of numbers from 0 to 10 in Python?

L = [x**2 for x in range(11)]

p.24
Lists and List Operations

What is the result of the expression [1, 2, 3] + [4, 5, 6]?

[1, 2, 3, 4, 5, 6]

p.25
Lists and List Operations

What does the list comprehension x=[z**2 for z in range(10) if z>4] output?

[25, 36, 49, 64, 81]

p.25
Lists and List Operations

What is the output of x=[x ** 2 for x in range(1, 11) if x % 2 == 1]?

[1, 9, 25, 49, 81]

p.10
Control Structures in Python

What happens if the boolean expression in an if statement evaluates to TRUE?

The block of statement(s) inside the if statement is executed.

p.35
Tuples and Their Properties

What is the value of T if T is a tuple and equals (5, 5)?

(5, 5)

p.22
Strings and String Operations

What is the purpose of the replace() method?

Replaces all occurrences of old in the string with new, or at most max occurrences if max is given.

p.29
Dictionaries and Dictionary Comprehensions

What does the values() method return?

It returns a new view of the dictionary's values.

p.29
Dictionaries and Dictionary Comprehensions

What does the remove() method do in a dictionary?

It removes or pops the specific item from the dictionary.

p.23
Lists and List Operations

What does the remove() method do in a list?

The remove() method removes the first item with the specified value.

p.32
Variables and Memory Management

Which of the following can be used as valid variable identifier(s) in Python? a. total b. 7Salute c. Que$tion d. global

a. total

p.17
Control Structures in Python

What is the output of the print statement in the first example?

School 1 is K, School 2 is V, School 3 is S, School 4 is C, School 5 is H

p.19
Control Structures in Python

What is the output of the nested for loop example provided?

The output is: 1 1 1 1 1 1 2 2 2 2 3 3 3 4 4 5

p.9
Functions and Modules

What is a Python module?

A Python module is a program file that contains Python code, including functions, classes, or variables, and is saved with the .py extension.

p.6
Control Structures in Python

What does the print() function do in Python?

It displays something on the screen/monitor.

p.27
Tuples and Their Properties

What does the index() method do in a tuple?

It returns the index of the first occurrence of a specified value in the tuple.

p.12
Control Structures in Python

What does the if-else statement do in Python?

It allows the program to execute one block of code if a condition is true and another block if it is false.

p.6
Control Structures in Python

In the expression x = 7 + 3 * 2, what value is assigned to x and why?

x is assigned 13 because multiplication has higher precedence than addition.

p.1
Characteristics of Python

What are some features that make Python powerful?

Dynamic typing, built-in types and tools, library utilities, third-party utilities (e.g., NumPy, SciPy), and automatic memory management.

p.1
Characteristics of Python

What does it mean that Python is portable and platform independent?

Python runs on virtually every major platform, and programs will run the same way as long as a compatible Python interpreter is installed.

p.1
Characteristics of Python

What makes Python easy to use and learn?

Python does not require an intermediate compiler, programs are compiled to byte code automatically, and its structure and syntax are intuitive.

p.1
Characteristics of Python

How is Python processed?

Python is processed at runtime by the Python interpreter.

p.34
Tuples and Their Properties

What is the output of the following code? T = (5, ) T = T*2 print(T)

(5, 5)

p.35
Variables and Memory Management

What will be printed if y is 30?

30

p.21
Strings and String Operations

What does x[::-1] return for the string 'computer'?

'retupmoc'

p.21
Strings and String Operations

What does the '+' operator do when used with strings?

It concatenates the strings.

p.23
Lists and List Operations

How are items accessed in a list?

Items in a list are accessed using indexes.

p.35
Lists and List Operations

What is the output of the range from 0 to 8?

0,1,2,3,4,5,6,7,8

p.24
Lists and List Operations

What does list1[:1] return when list1 = [1,2,3,4,5,6,7,8,9,10]?

[1]

p.33
Control Structures in Python

What is the output of the following code? A = 0 while A < 10:

The loop will execute 10 times, printing the value of A from 0 to 9.

p.29
Dictionaries and Dictionary Comprehensions

What does the update([other]) method do?

It updates the dictionary with the key/value pairs from other, overwriting existing keys.

p.3
Variables and Memory Management

Provide an example of assigning a string to a variable in Python.

c = 'John'

p.29
Dictionaries and Dictionary Comprehensions

What is the function of the del() method?

It deletes a particular item from the dictionary.

p.35
Lists and List Operations

How to remove an element from the list L as entered by the user?

Write Python code to remove an element as entered by the user from the list, L.

p.32
Lists and List Operations

The statement del l[1:3] does which of the following task?

b) delete 2nd and 3rd element from the list

p.12
Control Structures in Python

In the second example with a=10 and b=20, what will be printed?

The output will be 'B is Greater than A'.

p.4
Variables and Memory Management

What is the output of the code: x = 'Python is '; y = 'awesome'; z = x + y; print(z)?

The output is 'Python is awesome'.

p.12
Control Structures in Python

Can there be multiple elif statements following an if statement?

Yes, there can be an arbitrary number of elif statements following an if.

p.24
Lists and List Operations

What is the output of the expression list(Name) when Name = 'abcdefg'?

['a', 'b', 'c', 'd', 'e', 'f', 'g']

p.24
Lists and List Operations

What do the + and * operators do when used with lists in Python?

They perform concatenation and repetition, resulting in a new list.

p.25
Lists and List Operations

What is list comprehension in Python?

A way to create a new list using an existing list with the syntax: NewList = [ expression for variable in iterableobject if condition == True ]

p.3
Python Data Types

What does the None type represent in Python?

A special type with an unidentified value or absence of value.

p.34
Lists and List Operations

What is the output of the following code? L = [1,2,3,4,5,6,7,8,9] print(L[:-1])

[1, 2, 3, 4, 5, 6, 7, 8]

p.34
Strings and String Operations

What is the output of the following code? S = 'abcdefgh' L = list(S) print(L[1:4])

['b', 'c', 'd']

p.24
Lists and List Operations

What is the output of list1[1:] if list1 = [1,2,3,4,5,6,7,8,9,10]?

[2, 3, 4, 5, 6, 7, 8, 9, 10]

p.33
Control Structures in Python

How many times will the following loop execute? A = 0 while True: print(A) A = A + 1

The loop will execute infinitely.

p.3
Variables and Memory Management

What operator is used to assign values to variables in Python?

The assignment operator (=).

p.3
Variables and Memory Management

Provide an example of assigning a floating point value to a variable in Python.

b = 1000.0

p.22
Strings and String Operations

What is the function of the find() method?

Finds the index of the first occurrence of a substring in another string.

p.22
Strings and String Operations

What does the startswith() method determine?

Determines if the string or a substring starts with a specified substring; returns true if so, false otherwise.

p.32
Strings and String Operations

What will be the output of print('hello-' + 'how-are-you')?

hello-how-are-you

p.34
Error Handling and Exceptions

What kind of error message will be generated if the following code is executed? A = 5 B = 'hi' d = A+B print(D)

NameError: name 'D' is not defined

p.35
Error Handling and Exceptions

What will be printed if y is not defined?

* * * * * *

p.8
Error Handling and Exceptions

What is a run-time error in Python?

A run-time error happens when Python understands the code but encounters trouble when executing it.

p.21
Strings and String Operations

What is the function of the '*' operator when used with strings?

It causes repetition of the characters the specified number of times.

p.3
Python Data Types

What are mappings in Python?

Dictionaries, which consist of key-value pairs where keys are used to access values.

p.22
Strings and String Operations

What does the istitle() method check?

Returns true if the string is properly 'titlecased'; false otherwise.

p.35
Error Handling and Exceptions

What error occurs if an operation is performed on incompatible types?

TypeError

p.23
Lists and List Operations

What does the extend() method do?

The extend() method adds the elements of a list (or any iterable) to the end of the current list.

p.35
Lists and List Operations

What is the Python code to sort a list L in reverse order?

L.sort(reverse=True)

p.23
Lists and List Operations

What is the output of print(list1) if list1 is defined as [1,2,3,'A','B',7,8,[10,11]]?

The output will be [1, 2, 3, 'A', 'B', 7, 8, [10, 11]].

p.32
Lists and List Operations

Which of the following method is used to delete element from the list?

c) pop()

p.3
Python Data Types

What is the purpose of Boolean data type in Python?

To represent True or False values, typically used in comparisons.

p.34
Lists and List Operations

What is the output of the following code? L = [1,2,3,4,5,6,7,8,9] print(L[:])

[1, 2, 3, 4, 5, 6, 7, 8, 9]

p.35
Control Structures in Python

What will be printed if y is an infinite loop?

infinite loop. Condition / test expression is always True.

p.35
Lists and List Operations

What is the output of the range from 0 to 9?

0,1,2,3,4,5,6,7,8,9

p.25
Tuples and Their Properties

What is a tuple in Python?

A collection that is ordered and unchangeable, created by enclosing items within round brackets.

p.29
Dictionaries and Dictionary Comprehensions

What happens when you use the pop(key[,d]) method?

It removes the item with key and returns its value or d if key is not found. Raises KeyError if d is not provided and key is not found.

p.35
Lists and List Operations

What is the output of the list [1,2,3,4,5,6,7,8]?

[1,2,3,4,5,6,7,8]

p.32
Strings and String Operations

What will be the output of print('hello', 'how', 'are', 'you' + '-' * 4)?

hello how are you----

p.29
Dictionaries and Dictionary Comprehensions

What does the fromkeys(seq[, v]) method return?

It returns a new dictionary with keys from seq and value equal to v (defaults to None).

p.29
Dictionaries and Dictionary Comprehensions

What does the get(key[,d]) method do?

It returns the value of key. If key does not exist, it returns d (defaults to None).

p.23
Lists and List Operations

What does it mean that lists are mutable?

It means that the contents of a list can be changed after it is created.

p.3
Variables and Memory Management

What is the difference between mutable and immutable types?

Mutable types can be changed after creation, while immutable types cannot.

p.29
Dictionaries and Dictionary Comprehensions

What does the popitem() method do?

It removes and returns an arbitrary item (key, value). Raises KeyError if the dictionary is empty.

p.3
Variables and Memory Management

Provide an example of a multi-line string assignment in Python.

d = '''Hello world good morning'''

p.35
Dictionaries and Dictionary Comprehensions

How to display all items of the dictionary D as individual tuples?

D = {'A': 20, 'B': 30, 'C': 40, 'D': 50}

p.22
Strings and String Operations

What is the function of the isnumeric() method?

Returns true if the string contains only numeric characters; false otherwise.

p.23
Lists and List Operations

What does the append() method do in a list?

The append() method adds an element at the end of the list.

p.25
Tuples and Their Properties

When should you use a tuple instead of a list?

When the contents shouldn't change, to prevent items from being accidentally added, changed, or deleted.

p.35
Lists and List Operations

What is the output of the list [1,2,3,4,5,6,7,8,9]?

[1,2,3,4,5,6,7,8,9]

p.35
Variables and Memory Management

What is the output of the expression 1 + 1?

1 1

p.29
Dictionaries and Dictionary Comprehensions

What is the syntax for creating a dictionary comprehension?

The syntax is <dictionary> = { expression for <variable> in sequence }.

p.32
Python Data Types

Which of the following forces an expression to be converted into specific type?

d) Explicit type casting

p.34
Lists and List Operations

What is the output of the following code? L = [1,2,3,4,5,6,7,8,9] print(L.count(2)) print(L.index(2))

1 1

p.10
Control Structures in Python

What happens if the boolean expression in an if statement evaluates to FALSE?

The first set of code after the end of the if statement(s) is executed.

p.23
Lists and List Operations

What does the copy() method return?

The copy() method returns a copy of the list.

p.23
Lists and List Operations

What will be the output of print(x) if x is defined as list()?

The output will be x [], indicating an empty list.

p.32
Strings and String Operations

What will be the output of print('hello', 'how', 'are', 'you')?

hello how are you

p.32
Control Structures in Python

What does the step argument in range() function indicate?

It indicates the increment between each number in the sequence.

p.22
Strings and String Operations

What does the split() method do?

Splits the string according to a delimiter (space if not provided) and returns a list of substrings.

p.22
Strings and String Operations

What does the swapcase() method do?

Converts lowercase letters in a string to uppercase and vice versa.

p.23
Lists and List Operations

What does the sort() method do?

The sort() method sorts the list.

p.32
Lists and List Operations

Which of the following statement is true for extend() list method?

c) adds multiple elements at last

p.23
Lists and List Operations

What does the index() method return?

The index() method returns the index of the first element with the specified value.

p.35
Tuples and Their Properties

What is the tuple if the output is (4, 5, 66, 9)?

(4, 5, 66, 9)

p.32
Control Structures in Python

Which of the following statement is correct for an AND operator?

a) Python only evaluates the second argument if the first one is False

p.29
Dictionaries and Dictionary Comprehensions

How do you get the length of a dictionary?

You use the len() method to get the length of the dictionary.

Study Smarter, Not Harder
Study Smarter, Not Harder