0% found this document useful (0 votes)
5 views14 pages

PHP & Python +++ by Domnova

Uploaded by

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

PHP & Python +++ by Domnova

Uploaded by

ofnamale
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PHP & Python MCQs with Answers

1. Which of the following is the correct way to start a PHP block?


A) <php>
B) <?php ?> +++
C) <script lang='php'>
D) <? ?>

2. What is the correct way to declare a variable in PHP?


A) int $x = 5;
B) $x = 5; +++
C) x = 5;
D) var $x = 5;

3. Which of the following is NOT a valid PHP variable name?


A) $_name
B) $Name1
C) $1name +++
D) $name_1

4. Which operator is used for string concatenation in PHP?


A) +
B) . +++
C) &
D) ,

5. What is the output of:


echo 5 . "10";
A) 510 +++
B) 15
C) 5 10
D) Error

6. Which function is used to count the number of elements in an array?


A) sizeof()
B) count()
C) length()
D) sizeof() and count() +++

7. What will echo gettype(12.0); output?


A) integer
B) double +++
C) float
D) decimal

8. Which of the following is a superglobal in PHP?


A) $_POST
B) $GLOBALS
C) $_SERVER
D) All of the above +++
9. Which function is used to check if a variable is set?
A) empty()
B) isset() +++
C) defined()
D) var_exists()

10. Which of the following is the correct way to write a comment in PHP?
A) <!-- Comment -->
B) # Comment
C) // Comment
D) Both B and C +++

11. Which of these is the correct file extension for Python files?
A) .pyth
B) .pt
C) .py +++
D) .pyt

12. What is the output of print(type([]))?


A) <class 'list'> +++
B) <class 'dict'>
C) <class 'tuple'>
D) <class 'set'>

13. Which of the following is immutable in Python?


A) list
B) dict
C) tuple +++
D) set

14. What will print(2 ** 3 ** 2) output?


A) 64
B) 512 +++
C) 256
D) 36

15. What is the output of print("5" * 3)?


A) 15
B) 555 +++
C) "15"
D) Error

16. Which keyword is used to define a function in Python?


A) fun
B) def +++
C) function
D) define

17. What will print(type({})) output?


A) dict +++
B) set
C) list
D) tuple

18. What is the correct way to create a set in Python?


A) {1,2,3}
B) set([1,2,3])
C) set()
D) All of the above +++

19. What is the output of print(bool(""))?


A) True
B) False +++
C) None
D) Error

20. Which of these is used for single-line comments in Python?


A) //
B) ``
C) # +++
D) /* */

21. What is the output of:


echo "5" + "5";
A) 55
B) 10 +++
C) "10"
D) Error

22. Which of the following converts a string to lowercase?


A) strtolower() +++
B) lc()
C) toLower()
D) lower()

23. What does explode(",", "a,b,c"); return?


A) ["a,b,c"]
B) ["a","b","c"] +++
C) ["a|b|c"]
D) Error
24. Which function checks if a file exists in PHP?
A) file_exists() +++
B) is_file()
C) exist_file()
D) check_file()

25. What is the output of:


echo 5 == "5";
A) true +++
B) false
C) Error
D) null

26. Which loop executes at least once regardless of condition?


A) for
B) while
C) do...while +++
D) foreach

27. Which of the following is used to create a constant?


A) let()
B) define()
C) constant()
D) const() and define() +++

28. What is the output of:


echo round(4.6);
A) 4
B) 5 +++
C) 4.60
D) Error

29. Which function is used to open a file in PHP?


A) file()
B) fopen() +++
C) open()
D) readfile()

30. Which error control operator suppresses error messages?


A) !
B) @ +++
C) #
D) ~
31. Which of the following is true about print in PHP?
A) Can return a value +++
B) Faster than echo
C) Can take multiple parameters
D) Outputs arrays directly

32. What is the output of:


echo (int) 7.9;
A) 7.9
B) 8
C) 7 +++
D) Error
33. Which function generates a unique ID in PHP?
A) uniqid() +++
B) md5()
C) unique()
D) rand()

34. Which of these operators is used for exponentiation in PHP 7+?


A) ^
B) ** +++
C) pow
D) ^^

35. Which statement is correct about arrays in PHP?


A) Arrays can only hold numbers
B) Arrays are fixed-size
C) Arrays can hold mixed data types +++
D) Arrays are 1-based indexed by default

36. Which of these is used to terminate script execution?


A) exit() +++
B) stop()
C) halt()
D) break()

37. What is the output of:


echo true + true;
A) 1
B) 2 +++
C) true
D) Error

38. What is the correct way to start a PHP session?


A) start_session()
B) session_start() +++
C) begin_session()
D) session()

39. Which of these can be used to send output to the browser?


A) echo
B) print
C) printf
D) All of the above +++

40. Which function returns the last error message?


A) error_get_last() +++
B) last_error()
C) get_error()
D) error_log()

41. Which function is used to hash a password in PHP 7+?


A) md5()
B) crypt()
C) password_hash() +++
D) hash()

42. What will this return?


is_numeric("12e3");
A) true +++
B) false
C) null
D) Error

43. Which function can convert a JSON string to PHP array?


A) json_encode()
B) json_decode() +++
C) json_to_array()
D) decode_json()

44. Which keyword is used to inherit a class in PHP?


A) extends +++
B) implements
C) inherits
D) class

45. Which function is used to get the length of an array?


A) length()
B) sizeof()
C) strlen()
D) count() and sizeof() +++
46. Which of these functions sends an HTTP header?
A) http()
B) header() +++
C) send_header()
D) response()

47. Which function destroys all session data?


A) session_end()
B) session_destroy() +++
C) destroy_session()
D) unset_session()
48. Which of these correctly defines a constant?
A) $PI = 3.14;
B) const PI = 3.14; +++
C) constant("PI",3.14);
D) define PI=3.14;

49. What is the output of:


echo "Hello" === "Hello";
A) true +++
B) 1
C) false
D) Error

50. What is the correct way to check if $arr is an array?


A) is_array($arr) +++
B) array($arr)
C) check_array($arr)
D) isset($arr)

51. Which of these is the correct file extension for Python files?
A) .pyth
B) .pt
C) .py +++
D) .pyt

52. What is the output of print(type([]))?


A) <class 'list'> +++
B) <class 'dict'>
C) <class 'tuple'>
D) <class 'set'>

53. Which of the following is immutable in Python?


A) list
B) dict
C) tuple +++
D) set

54. What will print(2 ** 3 ** 2) output?


A) 64
B) 512 +++
C) 256
D) 36

55. What is the output of print("5" * 3)?


A) 15
B) 555 +++
C) "15"
D) Error

56. Which keyword is used to define a function in Python?


A) fun
B) def +++
C) function
D) define

57. What will print(type({})) output?


A) dict +++
B) set
C) list
D) tuple

58. What is the correct way to create a set in Python?


A) {1,2,3}
B) set([1,2,3])
C) set()
D) All of the above +++

59. What is the output of print(bool(""))?


A) True
B) False +++
C) None
D) Error

60. Which of these is used for single-line comments in Python?


A) //
B) ``
C) # +++
D) /* */

61. What will print(0.1 + 0.2 == 0.3) return?


A) True
B) False +++
C) 0.3
D) Error

62. What is the output of print("abc"[1])?


A) a
B) b +++
C) c
D) Error

63. What will print(len("Python")) output?


A) 5
B) 6 +++
C) 7
D) Error

64. Which of these is not a valid Python data type?


A) int
B) real +++
C) float
D) complex

65. Which operator is used for floor division in Python?


A) /
B) // +++
C) %
D) **

66. What is the output of print([1,2,3] * 2)?


A) [2,4,6]
B) [1,2,3,1,2,3] +++
C) Error
D) [[1,2,3],[1,2,3]]

67. Which of the following is false about Python?


A) It is interpreted
B) It is compiled +++
C) It is dynamically typed
D) It supports OOP

68. What is the output of print(type(lambda x: x))?


A) function +++
B) lambda
C) method
D) class
69. Which of these is a Python tuple?
A) (1,2,3) +++
B) [1,2,3]
C) {1,2,3}
D) {"a":1,"b":2}

70. What is the output of print(list("123"))?


A) [123]
B) ["123"]
C) ['1','2','3'] +++
D) Error

71. What will print(5 == 5.0) output?


A) True +++
B) False
C) Error
D) None

72. What is the output of print(type(range(5)))?


A) list
B) range +++
C) tuple
D) generator

73. Which function converts a string to an integer?


A) int() +++
B) str()
C) float()
D) chr()

74. What is the output of print(bool([]))?


A) True
B) False +++
C) []
D) None

75. Which keyword is used to handle exceptions?


A) catch
B) try
C) except
D) Both B and C +++

76. What is the output of print(5 // 2)?


A) 2 +++
B) 2.5
C) 3
D) Error

77. Which of these opens a file for writing in Python?


A) open("[Link]","r")
B) open("[Link]","w") +++
C) open("[Link]","rw")
D) open("[Link]")

78. Which module is used for regular expressions in Python?


A) regex
B) pyregex
C) re +++
D) regexp

79. What is the output of print(type(True))?


A) bool +++
B) int
C) str
D) NoneType

80. What is the output of print(3 * 'ab')?


A) ababab +++
B) 9
C) ['ab','ab','ab']
D) Error

81. Which is not a Python keyword?


A) with
B) yield
C) var +++
D) pass

82. What will print(int("10") + float("2.5")) output?


A) 12.5 +++
B) 102.5
C) 10.25
D) Error

83. What is the output of print(list({1: "a", 2: "b"}))?


A) [1,2] +++
B) ["a","b"]
C) [(1,"a"),(2,"b")]
D) Error
84. Which of these is used to create a virtual environment?
A) pip install venv
B) python -m venv env +++
C) virtual env
D) mkvirtualenv

85. What is the output of print("hello".capitalize())?


A) Hello +++
B) HELLO
C) hello
D) Error

86. Which function returns the absolute value?


A) fabs()
B) abs() +++
C) absolute()
D) val()

87. What is the output of print(len(set([1,2,2,3])))?


A) 3 +++
B) 4
C) [1,2,3]
D) Error

88. What is the output of print("Python".find("t"))?


A) 1 +++
B) 2
C) -1
D) Error

89. Which operator is used for exponentiation in Python?


A) ^
B) ** +++
C) pow
D) ^^

90. What is the output of print(type((1)))?


A) int +++
B) tuple
C) list
D) Error

91. What is the output of print(type((1,)))?


A) int
B) tuple +++
C) list
D) set

92. Which function is used to get the length of a string in Python?


A) size()
B) length()
C) len() +++
D) strlen()

93. What is the output of print(10 % 3)?


A) 1 +++
B) 3
C) 10
D) 0

94. Which of the following is false about Python dictionaries?


A) Keys must be unique
B) Keys can be lists +++
C) Keys must be immutable
D) Values can be anything

95. What is the output of print("1,2,3".split(","))?


A) ['1,2,3']
B) ['1','2','3'] +++
C) [1,2,3]
D) Error

96. What is the output of print(isinstance(5,bool))?


A) True
B) False +++
C) None
D) Error

97. Which of these is used to define a class in Python?


A) class +++
B) defclass
C) struct
D) object

98. What is the output of print(all([True,1,"a"]))?


A) True +++
B) False
C) "a"
D) Error
99. Which of these is not a core data type in Python?
A) int
B) float
C) array +++
D) str

100. What is the output of print(type(open("[Link]","w")))?


A) file
B) str
C) _io.TextIOWrapper +++
D) stream

You might also like