Python Language QuizBy digitalcollegelibrary.com / 18 March 2024 In this Python Language Quiz Section - Every Question carries 2 Marks. If any Question/Answer will be wrong then 2 Marks will be deducted. Note : - Fill information correctly to get Certified. Python Quiz 1 / 50 Choose the correct syntax for reading from a text file stored in ‘‘c:\scores.txt'' ? Infile = open(''c:scores.txt'',''r'') Infile = open(file=''c:\scores.txt'', ''r'') Infile = open.file(''c:\scores.txt'',''r'') Infile = open(''c:\scores.txt'', ''r'') 2 / 50 Which of the following is a correct way to comment multiple lines in Python? /* Comment */ # Comment ''' Comment ''' // Comment 3 / 50 In Python, which of the following data types is immutable? List Dictionary Set Tuple 4 / 50 Which of the following is used to get user input in Python? get_input() input() user_input() receive_input() 5 / 50 Which keyword is used to define a function in Python? func define function def 6 / 50 Which of the following statements is true about Python? It is a low-level language It must be compiled before execution It is dynamically typed It is primarily used for system programming 7 / 50 Which of the following is used to open a file in Python? open_file() file_open() open() read_file() 8 / 50 Which of the following is not a valid data type in Python? int string double tuple 9 / 50 Which of the following is the correct way to check if two variables refer to the same object in memory? x is y x == y x.equals(y) x is not y 10 / 50 Which of the following is used to remove the last element from a list in Python? remove() pop() delete() del 11 / 50 Which of the following is the correct way to define a tuple in Python? (1, 2, 3) [1, 2, 3] {1, 2, 3} 1, 2, 3 12 / 50 Which of the following is used to concatenate two strings in Python? + operator .concat() method concat() function concatenate() method 13 / 50 Which of the following is the correct way to declare a list in Python? list = {1, 2, 3} list = [1, 2, 3] list = (1, 2, 3) list = "1, 2, 3" 14 / 50 Which of the following is a correct way to define a dictionary in Python? {1: 'one', 2: 'two'} [1: 'one', 2: 'two'] (1: 'one', 2: 'two') 15 / 50 Which of the following is the correct way to access the value associated with a key in a dictionary? dictionary[key] dictionary.key dictionary.get(key) dictionary[value] 16 / 50 Which of the following is a correct way to check if a key exists in a dictionary? key in dictionary dictionary.exists(key) dictionary.hasKey(key) key.exists(dictionary) 17 / 50 Which of the following is used to remove an element from a set in Python? remov() discard() pop() del 18 / 50 Which of the following is used to remove the first occurrence of a value from a list in Python? remove() pop() delete() del 19 / 50 Which of the following is the correct way to define a set in Python? {1, 2, 3} [1, 2, 3] (1, 2, 3) 1, 2, 3 20 / 50 Which of the following is the correct way to remove an item from a dictionary in Python? dictionary.remove(key) del dictionary[key] dictionary.pop(key) remove(dictionary[key]) 21 / 50 Which of the following is the correct way to concatenate two lists in Python? list1.concat(list2) list1 + list2 concat(list1, list2) list1.append(list2) 22 / 50 Which of the following is used to convert a string to uppercase in Python? upper() to_upper() uppercase() toUpperCase() 23 / 50 Which of the following is used to convert a string to lowercase in Python? lower() to_lower() to_lower() toLowerCase() 24 / 50 Which of the following is used to split a string into a list in Python? split() split_string() to_list() string_to_list() 25 / 50 Which of the following is used to find the length of a string in Python? length() len() size() string_length() 26 / 50 Which of the following operators is used for exponentiation in Python? ** *** ^ ^^ 27 / 50 Which of the following statements is used to exit from a loop in Python? exit break stop end 28 / 50 Which of the following is the correct way to define a function in Python with parameters? def my_function(): function my_function(): def my_function(param1, param2): function my_function(param1, param2): 29 / 50 Which of the following methods is used to add an element at the end of a list in Python? append() add() insert() extend() 30 / 50 Which of the following is the correct way to check if a string contains a substring in Python? string.contains(substring) substring.in(string) string.find(substring) substring in string 31 / 50 Which of the following is the correct way to create an empty set in Python? set() {} empty_set() {[]} 32 / 50 Which of the following methods is used to remove an arbitrary item from a set in Python? pop() remove() discard() clear() 33 / 50 Which of the following is the correct way to create a tuple with a single element in Python? (1) (1,) (1, 2) 1, 34 / 50 Which of the following is the correct way to access the last element of a list in Python? x[len(x)] x[-1] x[last] x.last 35 / 50 Which of the following methods is used to join elements of a list into a single string in Python? join() concat() merge() combine() 36 / 50 Which of the following is the correct way to add a key-value pair to a dictionary in Python? dictionary.add(key, value) dictionary.insert(key, value) dictionary[key] = value dictionary.put(key, value) 37 / 50 Which of the following is used to repeat a string in Python? repeat() replicate() * operator repeat_string() 38 / 50 Which of the following is the correct way to convert a string to a list of characters in Python? list(x) x.to_list() split(x) x.split() 39 / 50 Which of the following is the correct way to iterate over a dictionary in Python? for key in dictionary.keys(): for key in dictionary: for key in dictionary.values(): for key, value in dictionary: 40 / 50 Which of the following methods is used to remove an item from a list by its index in Python? remove() delete() pop() discard() 41 / 50 Which of the following is the correct way to access the first element of a tuple in Python? x[0] x.first() x.get(0) x.first 42 / 50 Which of the following is the correct way to concatenate two dictionaries in Python 3.5+? dict1.concat(dict2) dict1 + dict2 dict1.append(dict2) {**dict1, **dict2} 43 / 50 Which of the following methods is used to convert a list to a set in Python? to_set() set() convert_to_set() list_to_set() 44 / 50 Which of the following methods is used to sort elements of a list in Python? sort() sorted() order() arrange() 45 / 50 What command is used to insert 6 in a list ‘‘L'' at 3rd position ? L.insert(2,6) L.insert(3,6) L.add(3,6) L.append(2,6) 46 / 50 Which of the following is false statement in python int(144)==144 int('144')==144 int(144.0)==144 None of the above 47 / 50 What is output for −' ' in 'python' ? 'python' False Name error True 48 / 50 Which of the following is not correct about the Serialization? It converts the data into human readable form using Pickler The process is also called flattening We can use the JSON module to do serialization None of the above 49 / 50 Which of the following is not an argument of the dumps function? obj file fix_imports protocol 50 / 50 Which of the following are not the constants in the Pickle module? HIGHEST_PROTOCOL DEFAULT_PROTOCOL LOWEST_PROTOCOL None of the above Your score isThe average score is 65% 0% Restart quiz