Assignment 2 Pregrad
Assignment 2 Pregrad
x = "Hello, World!"
print(x[2:6])
a) Hello
b) llo,
c) llo
d) ll
a) variableName = value
b) value = variableName
c) variableName: value
d) value : variableName
a) func
b) define
c) function
d) def
x=5
y = "John"
print(x + y)
a) 5John
b) John5
a) //
b) /*
c) #
d) --
a) (1, 2, 3)
b) {1, 2, 3}
c) [1, 2, 3]
d) 1, 2, 3
a) { }
b) ( )
c) [ ]
d) Indentation
print(10 > 9)
a) 10
b) 9
c) True
d) False
b) String
c) Integer
d) List
a) append()
b) extend()
c) insert()
d) add()
x = "Hello, World!"
print(x[2:5])
a) Prints "Hello"
b) Prints "llo"
c) Prints "llo,"
a) ^
b) **
c) %
d) //
16.What is the correct syntax for a Python function that takes no arguments?
a) def my_function():
b) def my_function(void):
c) def my_function(void):
d) def my_function(None):
17.What method is used to remove the last item from a list in Python?
a) pop()
b) remove()
c) clear()
d) del()
x = "Hello, World!"
print(x[-5:-2])
a) "Wor"
b) "orl"
c) "rld"
d) "Worl"
a) function
b) define
c) def
d) fun
x[1] = "kiwi"
d) Throws an error
a) length()
b) len()
c) size()
d) count()
x=5
y=2
print(x / y)
a) 2.5
b) 2
c) 2.0
d) 2.2
a) lower()
b) toLower()
c) lowercase()
d) caseLower()
x=5
y = "2"
print(x + int(y))
a) 7
b) 52
c) Error
d) None
26. Which method is used to join elements of a list into a string in Python?
a) join()
b) concatenate()
c) merge()
d) combine()
27. What is the correct way to check if two variables are pointing to the same object in memory in
Python?
a) x is y
b) x == y
c) x.equals(y)
d) x is not y
x = [1, 2, 3]
y = x.copy()
y[0] = 4
print(x)
a) [1, 2, 3]
b) [4, 2, 3]
c) [1, 4, 3]
d) [4, 4, 4]
a) split()
b) explode()
c) divide()
d) slice()
x = 10
y=3
print(x // y)
a) 3.3333
b) 3.0
c) 1
d) 0