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

Python 21 One Marks

Python

Uploaded by

Dhinesh T
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Python 21 One Marks

Python

Uploaded by

Dhinesh T
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

21 one marks

1. Which of the following is a valid if statement in Python?

a) If (x > 5) then:

b) If x > 5:

c) If x > 5 then:

d) If x > 5 then

2. Which statement is used to exit a loop immediately in Python?

a) Skip

b) Stop

c) Break

d) Exit
3. What is the output of the following code?

X=3

If x > 5:

Print(“Greater”)

Else:

Print(“Smaller”)

a) Greater

b) Smaller

c) Error

d) None

4. Which of the following keywords is used to create an infinite loop?

a) While 0
b) For x in range(0)

c) While True

d) Repeat

5. In Python, which statement is used to handle exceptions?

a) Catch

b) Except

c) Throw

d) Try

6. What will print(“hello”.upper()) output?

a) HELLO

b) Hello
c) Hello

d) Error

7. Which method is used to find the length of a string?

a) Count()

b) Length()

c) Len()

d) Size()

8. What does print(“hello” * 3) output?

a) Hellohellohello

b) Hello 3
c) Hello, hello, hello

d) Error

9. Which method can be used to replace a substring in a string?

a) Replace()

b) Substitute()

c) Swap()

d) Change()

10. What will print(“abcdef”[2:5]) output?

a) Cde
b) Bcde

c) C

d) Error

11. Which of the following methods checks if a string contains only alphabets?

A) Isalpha()

b) Isnum()

c) Isdigit()

d) Isalnum()

12. What will print(“hello”.find(“e”)) output?

a) 1
b) 2

c) 0

d) -1

13. How can you remove whitespace from the beginning and end of a string?

a) Strip()

b) Trim()

c) Clean()

d) Cu

e)

14. How do you create a list in Python?

a) List = {1, 2, 3}
b) List = [1, 2, 3]

c) List = (1, 2, 3)

d) List = <1, 2, 3>

15. What will print([1, 2, 3][1]) output?

a) 1

b) 2

c) 3

d) Error

16. Which method adds an item to the end of a list?

a) Add()
b) Append()

c) Insert()

d) Push()

17. What will print([1, 2, 3] + [4, 5]) output?

a) [1, 2, 3, 4, 5]

b) [1, 2, 3, [4, 5]]

c) [5, 4, 3, 2, 1]

d) Error

18. Which method removes the last element of a list?


a) Delete()

b) Pop()

c) Remove()

d) Discard()

19. What will print(len([1, 2, 3, 4])) output?

a) 4

b) 3

c) 5

d) Error

20. Which method would you use to sort a list in ascending order?
a) Sort()

b) Order()

c) Arrange()

d) Ascend()

21. How can you access the last item in a list my_list?

a) My_list[len(my_list)]

b) My_list[-1]

c) My_list[1]

d) My_list.last()

You might also like