Python Questions PDF
Document Details
Uploaded by WholesomeBalalaika7284
Высший медицинский колледж
Tags
Summary
This document contains multiple-choice questions covering various aspects of Python programming, including basic concepts, functions, data structures, and more.
Full Transcript
**1. What is the primary purpose of a variable in Python?** **2. What is the correct syntax to display \"Hello, World!\" in Python?** **3. Which data type is used to store a sequence of characters in Python?** **4. What is the purpose of the input() function in Python?** **5. How do you create a...
**1. What is the primary purpose of a variable in Python?** **2. What is the correct syntax to display \"Hello, World!\" in Python?** **3. Which data type is used to store a sequence of characters in Python?** **4. What is the purpose of the input() function in Python?** **5. How do you create a list in Python?** **6. Which Python operator is used for addition?** **7. What is the correct syntax for a while loop in Python?** **8. Which of the following is used to comment out a line in Python?** **9. How do you create a function in Python?** **10. Which Python method can be used to add an item to the end of a list?** **11. What is the output of print(2 \*\* 3)?** **12. Which of the following is the correct way to declare a variable that holds a floating-point number in Python?** **13. What is the correct way to start a Python program?** **14. How do you create a comment that spans multiple lines in Python?** **15. Which data type is used to store multiple values in Python?** **16. What will be the output of print(type(5)) in Python?** **17. Which Python function is used to return the length of a string or list?** **18. Which of these is an immutable data type in Python?** **19. Which method would you use to remove an item from a list in Python?** **20. What does the break statement do in Python?** **21. Which of the following is used to import a Python module?** **22. Which of the following is the correct syntax for an if statement in Python?** **23. Which operator is used for comparison in Python?** **24. What is the correct way to write an else statement in Python?** **25. Which method in Python is used to convert a string to uppercase?** **26. Which statement is used to handle exceptions in Python?** **27. Which of the following is the correct syntax for defining a class in Python?** **28. What does the continue statement do in a loop in Python?** **29. Which of these is a valid way to create a dictionary in Python?** **30. What will be the output of print(5 // 2)?** **31. Which function is used to read input from the user in Python?** **32. What is the correct syntax for a for loop in Python?** **33. Which of these is not a valid Python data type?** **34. What will the following Python code output: print(\"Hello\" \* 3)?** **35. Which method is used to remove whitespace from the beginning and end of a string in Python?** **36. How do you write a single-line comment in Python?** **37. What is the result of 10 % 3 in Python?** **38. How do you handle exceptions in Python?** **39. Which of the following is the correct way to define a class in Python?** **40. Which statement is used to exit a loop in Python?** **41. Which method is used to add an element to the end of a list?** **42. What does len() function do in Python?** **43. Which of the following is the correct way to create a tuple?** **44. What is the correct way to check if a value is in a list in Python?** **45. What does the range() function do in Python?** **46. What is the result of the following code: print(\"abc\" + \"def\")?** **47. Which Python method is used to find the index of an element in a list?** **48. How do you make a string lowercase in Python?** **49. Which of the following Python functions converts a string to a number?** **50. Which keyword is used to define a function in Python?** **51. What will print(2 + 3 \* 4) output?** **52. What is the output of print(2 == 2)?** **53. Which of the following is used to define a dictionary in Python?** **54. How do you access the first element of a list my\_list = \[10, 20, 30\]?** **55. How do you check if a string is empty in Python?** **56. What will print(\"Python\" == \"python\") output?** **57. Which of the following will create a list of numbers from 1 to 10 in Python?** **58. Which method is used to remove an item from a dictionary in Python?** **59. What does the continue statement do in a loop?** **61. Which function is used to determine the type of an object in Python?** **62. What will the following code output? print(bool(\"\"))** **63. How do you start a Python script file?** **64. What will print(\[1, 2, 3\] + \[4, 5\]) output?** **65. Which operator is used to repeat a string multiple times in Python?** **66. What does the is operator do in Python?** **67. Which function is used to round a number in Python?** **68. How do you create an empty set in Python?** **69. What is the output of print(4 // 3)?** **70. What will print(\"Python\".find(\"P\")) output?** **71. What is the correct way to define a dictionary in Python?** **72. Which Python keyword is used to create a generator?** **73. What does list.pop() do?** **74. Which keyword is used to check for membership in a sequence?** **75. What is the output of print(\"PYTHON\".lower())?** **76. Which Python method is used to replace parts of a string?** **77. What will print(list(range(5))) output?** **78. Which method removes all items from a list?** **79. How do you add an item to a set in Python?** **80. Which function can convert a list into a set?** **81. What is the purpose of the not keyword in Python?** **82. What is the output of print(type(\[1, 2, 3\]))?** **83. Which function can you use to iterate over both keys and values of a dictionary?** **84. What will the following code output? print(10 / 4)** **85. Which of the following represents a valid Python module?** **86. How do you handle multiple exceptions in a single try block?** **87. Which of the following will check if a string starts with a specific prefix?** **88. What will print(\"5\" + \"5\") output?** **89. What is the correct way to define a multi-line string in Python?** **90. What does the enumerate() function do in Python?** **91. Which keyword is used to define an anonymous function in Python?** **92. What is the output of print(4 \*\* 0.5)?** **93. Which method is used to get all the keys of a dictionary?** **94. Which data type is unordered in Python?** **95. What is the default value of a boolean in Python?** **96. What will print(bool(0)) output?** **97. What is the correct way to open a file for writing in Python?** **98. Which Python keyword is used to exit a function?** **99. How do you create a new line in a string in Python?** **100. What is the output of print(10 // 3)?** **81. What will print(type(\[\])) output?** **82. Which function is used to convert a number to a string in Python?** **83. What is the default starting index for Python lists?** **84. How do you remove an element by its index from a list?** **85. What does the max() function do?** **86. Which keyword is used to create a loop that continues as long as a condition is true?** **87. What will print(\"hello\".capitalize()) output?** **88. What is the result of print(4 \< 2 or 3 \> 1)?** **89. What does the split() method do?** **90. How do you check the number of elements in a list?** **91. Which of the following is a valid Python variable name?** **92. Which Python method converts a list into a string with a delimiter?** **93. What is the correct way to get the last element of a list?** **94. What does the startswith() method check in a string?** **95. What will print(\"a\" in \"apple\") output?** **96. How do you access the value associated with a key in a dictionary?** **97. Which function is used to sort a list permanently in Python?** **98. What is the output of print(bool(0))?** **99. Which of the following is NOT a valid Python loop?** **100. What is the result of the following code? print(5 in \[1, 2, 3, 4, 5\])** **101. Which Python function can be used to convert an integer to a string?** **102. Which method is used to count the number of occurrences of a substring in a string?** **103. What does the pass keyword do in Python?** **104. What will the following code output? print(type(10.5))** **105. Which Python method removes an item by its index from a list?**