0% found this document useful (0 votes)
4 views

pytho quiz

The document contains a series of questions and answers related to Python programming concepts, including variable declaration, data types, function creation, comments, and loop control. Key answers include that variables are declared using '=' and tuples are immutable. It also explains the output of specific code snippets and the nature of function arguments.

Uploaded by

pamidi.prameela
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

pytho quiz

The document contains a series of questions and answers related to Python programming concepts, including variable declaration, data types, function creation, comments, and loop control. Key answers include that variables are declared using '=' and tuples are immutable. It also explains the output of specific code snippets and the nature of function arguments.

Uploaded by

pamidi.prameela
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1. Which of the following is the correct way to declare a variable in Python?

a) int x = 10
b) x := 10
c) x = 10
d) var x = 10
2. Which of these data types is immutable in Python?
a) List
b) Set
c) Dictionary
d) Tuple
3. What is the output of the following code?
print(2 ** 3)
a) 6
b) 8
c) 9
d)12
4. Which of these is the correct way to create a function in Python?
a) def my_function{}
b) function my_function():
c) def my_function():
d) function: my_function()
5. How do you declare a comment in Python?
a) // This is a comment
b) # This is a comment
c) <!-- This is a comment -->
d) /* This is a comment */
6. What will the following code output?
def my_function(x, y=2):
return x + y
print(my_function(3))
a) 5
b) 3
c) 2
d) None

7.Which type of argument must always be passed when calling a function?

a) Default arguments
b) Positional arguments
c) Keyword arguments
d) Arbitrary arguments
8. How can you skip an iteration of a loop in Python?

a) return
b) skip
c) continue
d) pass

9. What will the following code output?

for i in range(2, 6, 2):


print(i)
a) 2 4
b) 2 3 4 5
c) 2 4 6
d) 1 2 3 4

10. Which of the following is used to define an infinite loop in Python?

a) while True:

b) for 1 in range(0, 1):

c) for True:

d) while False:
Answers

1. Answer:
c) x = 10
In Python, variables are assigned with the = operator.
2. Answer:
d) Tuple
Tuples are immutable, meaning their values cannot be changed after they are created.
3. Answer:
b) 8
2 ** 3 means 2 raised to the power of 3, which equals 8.
4. Answer:
c) def my_function():
This is the correct syntax for defining a function in Python.
5. Answer:
b) # This is a comment
In Python, comments are written using the # symbol.
6. Answer:
a) 5
The function takes one argument 3 and uses the default value y=2, so the result is 3 + 2 =
5.
7. Answer:
b) Positional arguments
Positional arguments are required unless default values are provided.
8. Answer:
c) continue
The continue statement is used to skip the current iteration of the loop and continue with
the next iteration.
9. Answer a) 2 4
The range(2, 6, 2) generates numbers starting from 2 up to (but not including) 6, with a step of 2,
i.e., 2 and 4.
10 Answer

a) while True:
A while True: loop will run infinitely unless a break condition is met.

You might also like