General Python
(Blank)
Data Structures
Functions
OOP
100

What is the output of this code?

x = 7
y = 3
print(x // y)



2

100

What will be the output of this code? 


x = 5
if x > 10:
    print("Greater than 10")
elif x == 5:
    print("Exactly 5")
else:
    print("Less than 5")


Exactly 5

100

What is the output of this code? 

fruits = ["apple", "banana", "cherry"]
print(fruits[-2])


banana

100

What will be the output of this code? 

def multiply(x, y=2):
    return x * y

print(multiply(3))


6

100

What is printed by this code? 


class A:
    def __init__(self):
        print("A is created")
a = A()


A is created

200

Which one is not a valid Python data type? 

  • a) int

  • b) float

  • c) double

  • d) tuple

c) real

200

How many times will "Aktau" be printed? 

for i in range(2, 7):
    print("Aktau")


5 times (for i = 2, 3, 4, 5, 6)

200

Given this tuple t = (1, 2, 3, 4), how do you change the first element to 10?

You can't — tuples are immutable.

200

Write a function called is_even that returns True if a number is even, otherwise False.

def is_even(n):
    return n % 2 == 0

200

What is method overriding?

When a subclass provides a new version of a method inherited from the parent class.

300

What (name of error) will happen if you run this code? 


print("Hello)


SyntaxError — missing closing quotation mark.

300

What will be printed? 

for letter in "Python":
    if letter == "h":
        continue
    print(letter)


P
y
t
o
n


300

Which method adds an element to the end of a list?

.append()

300

Write a simple function that takes two numbers and returns their sum.

def add(x,y):
    return x+y

300

What is the purpose of self in class methods?

self refers to the current instance (objects itself) of the class, allowing access to attributes and other methods.

400

How do you take input as an integer from a user and store it in a variable called age?

age = int(input())

400

Rewrite this for loop as a while loop:


for i in range(3):
    print(i)

 

i = 0
while i < 3:
    print(i)
    i += 1


400

How do you remove the key 'age' from a dictionary called person?

del person['age']

400

What happens if you define a function but forget to call it?

Nothing

400

What is the output? 


class Animal:
    def sound(self):
        return "Auuu!"

class Dog(Animal):
    def bark(self):
        return "Woof!"

d = Dog()
print(d.sound())


Auuu!

500

Write a Python expression that checks if a number n is between 10 and 20 both included.

10 <= n <= 20

500

What is wrong with this while loop? 

x = 1
while x < 5:
    print(x)


The loop is infinite because x is never updated inside the loop (no x += 1).

500

Sets automatically sort their elements.

False (sets are unordered, not sorted)

500

What keyword allows a function to accept any number of arguments?

*args

500

What is the difference between an attribute and a method in a class?

  • Attribute = describes the state or properties of an object (e.g., name, age, color) - variable

  • Method = defines the behavior or actions of an object (e.g., drive(), bark(), calculate()) - function