105 solutions available
Question 1Assertion. Lists and Tuples are similar sequence types of Python, yet they are two different data types.Reason. List sequences are mutable...
Question 2Assertion. Modifying a string creates another string internally but modifying a list does not create a new list.Reason. Strings store...
Question 3Assertion. Modifying a string creates another string internally but modifying a list does not create a new list.Reason. Strings are...
Question 4Assertion. Dictionaries are mutable, hence its keys can be easily changed.Reason. Mutability means a value can be changed in place without...
Question 5Assertion. Dictionaries are mutable but their keys are immutable.Reason. The values of a dictionary can change but keys of dictionary...
Question 6Assertion. In Insertion Sort, a part of the array is always sorted.Reason. In Insertion sort, each successive element is picked and...
Question 1Strings in Python store their individual letters in Memory in contiguous location.
Question 2Operator + when used with two strings, gives a concatenated string.
Question 3Operator + when used with a string and an integer gives an error.
Question 4Part of a string containing some contiguous characters from the string is called string slice.
Question 5The * operator when used with a list/string and an integer, replicates the list/string.
Question 6Tuples or Strings are not mutable while lists are.
Question 7Using list() function, you can make a true copy of a list.
Question 8The pop() function is used to remove an item from a list/dictionary.
Question 9The del statement can remove an individual item or a slice from a list.
Question 10The clear() function removes all the elements of a list/dictionary.
Question 11Creating a tuple from a set of values is called packing.
Question 12Creating individual values from a tuple's elements is called unpacking.
Question 13The keys() method returns all the keys in a dictionary.
Question 14The values() function returns all values from Key : value pair of a dictionary.
Question 15The items() function returns all the Key : value pairs as (key, value) sequences.
Question 1The numbered position of a letter in a string is called ...............positioninteger positionindexlocation
Question 2The operator ............... tells if an element is present in a sequence or not.existsinintoinside
Question 3The keys of a dictionary must be of ............... types.integermutableimmutableany of these
Question 4Following set of commands is executed in shell, what will be the output?>>>str = "hello" >>>str[:2]...
Question 5What data type is the object below ?L = [1, 23, 'hello', 1]listdictionaryarraytuple
Question 6What data type is the object below ?L = 1, 23, 'hello', 1listdictionaryarraytuple
Question 7To store values in terms of key and value, what core data type does Python provide ?listtupleclassdictionary
Question 8What is the value of the following expression ?3 + 3.00, 3**3.0(6.0, 27.0)(6.0, 9.00)(6, 27)[6.0, 27.0][6, 27]
Question 9List AL is defined as follows : AL = [1, 2, 3, 4, 5]Which of the following statements removes the middle element 3 from it so that the list...
Question 10Which two lines of code are valid strings in Python ?This is a string'This is a string'(This is a string)"This is a string"
Question 11You have the following code segment :String1 = "my" String2 = "work" print(String1 + String2)What is the output of this code?my...
Question 12You have the following code segment :String1 = "my" String2 = "work" print(String1+String2.upper())What is the output of this...
Question 13Which line of code produces an error ?"one" + 'two'1 + 2"one" + "2"'1' + 2
Question 14What is the output of this code ? >>> int("3" + "4")"7""34"3424
Question 15Which line of code will cause an error ?1. num= [5, 4, 3, [2], 1] 2. print(num[0]) 3. print(num[3][0]) 4. print(num[5])...
Question 16Which is the correct form of declaration of dictionary ?Day = {1:'Monday', 2:'Tuesday', 3:'wednesday'}Day = {1;'Monday', 2;'Tuesday',...
Question 17Identify the valid declaration of L:L = ['Mon', '23', 'hello', '60.5']dictionarystringtuplelist
Question 18Suppose a tuple T is declared as T = (10, 12, 43, 39), which of the following is incorrect ?print(T[1])T[2] = -29print(max(T))print(len(T))
Question 1Do both the following represent the same list.['a', 'b', 'c']['c', 'a', 'b']
Question 2A list may contain any type of objects except another list.
Question 3There is no conceptual limit to the size of a list.
Question 4All elements in a list must be of the same type.
Question 5A given object may appear in a list more than once.
Question 6The keys of a dictionary must be of immutable types.
Question 7You can combine a numeric value and a string by using the + symbol.
Question 8The clear( ) removes all the elements of a dictionary but does not delete the empty dictionary.
Question 9The max( ) and min( ) when used with tuples, can work if elements of the tuple are all of the same type.
Question 10A list of characters is similar to a string type.
Question 11For any index n, s[:n] + s[n:] will give you original string s.
Question 12A dictionary can contain keys of any valid Python types.
Question 1What is the internal structure of python strings ?
Question 2Write a python script that traverses through an input string and prints its characters in different lines - two characters per line.
Question 3Discuss the utility and significance of Lists, briefly.
Question 4What do you understand by mutability ? What does "in place" task mean ?
Question 5Start with the list [8, 9, 10]. Do the following using list functions:Set the second entry (index 1) to 17Add 4, 5 and 6 to the end of the...
Question 6What's a[1 : 1] if a is a string of at least two characters ? And what if string is shorter ?
Question 7What are the two ways to add something to a list ? How are they different ?
Question 8What are the two ways to remove something from a list? How are they different ?
Question 9What is the difference between a list and a tuple ?
Question 10In the Python shell, do the following :Define a variable named states that is an empty list.Add 'Delhi' to the list.Now add 'Punjab' to...
Question 11Discuss the utility and significance of Tuples, briefly.
Question 12If a is (1, 2, 3)what is the difference (if any) between a * 3 and (a, a, a) ?Is a * 3 equivalent to a + a + a ?what is the meaning of...
Question 13What is the difference between (30) and (30,) ?Answera = (30) ⇒ It will be treated as an integer expression, hence a stores an integer 30,...
Question 14Write a Python statement to declare a Dictionary named ClassRoll with Keys as 1, 2, 3 and corresponding values as 'Reena', 'Rakesh',...
Question 15Why is a dictionary termed as an unordered collection of objects ?
Question 16What type of objects can be used as keys in dictionaries ?
Question 17Though tuples are immutable type, yet they cannot always be used as keys in a dictionary. What is the condition to use tuples as a key in...
Question 18Dictionary is a mutable type, which means you can modify its contents ? What all is modifiable in a dictionary ? Can you modify the keys...
Question 19How is del D and del D[<key>] different from one another if D is a dictionary ?
Question 20Create a dictionary named D with three entries, for keys 'a', 'b' and 'c'. What happens if you try to index a nonexistent key (D['d']) ?...
Question 21What is sorting ? Name some popular sorting techniques.
Question 22Discuss Bubble sort and Insertion sort techniques.
Question 1(a)What will be the output produced by following code fragments ?y = str(123) x = "hello" \* 3 print(x, y) x = "hello" + "world" y...
Question 1(b)What will be the output produced by following code fragments ?x = "hello" + \ "to Python" + \ "world" for char in x : y =...
Question 1(c)What will be the output produced by following code fragments ?x = "hello world" print(x[:2], x[:-2], x[-2:]) print(x[6], x[2:4])...
Question 2Write a short Python code segment that adds up the lengths of all the words in a list and then prints the average (mean) length.
Question 3Predict the output of the following code snippet ?a = [1, 2, 3, 4, 5] print(a[3:0:-1])
Question 4(a)Predict the output of the following code snippet?arr = [1, 2, 3, 4, 5, 6] for i in range(1, 6): arr[i - 1] = arr[i] for i in...
Question 4(b)Predict the output of the following code snippet ?Numbers = [9, 18, 27, 36] for Num in Numbers : for N in range(1, Num % 8) :...
Question 5(a)Find the errors. State reasons.t = (1, "a", 9.2) t[0] = 6
Question 5(b)Find the errors. State reasons.t = [1, "a", 9.2] t[0] = 6
Question 5(c)Find the errors. State reasons.t = [1, "a", 9.2] t[4] = 6
Question 5(d)Find the errors. State reasons.t = 'hello' t[0] = "H"
Question 5(e)Find the errors. State reasons.for Name in [Amar, Shveta, Parag] IF Name[0] = 'S': print(Name)
Question 6Assuming words is a valid list of words, the program below tries to print the list in reverse. Does it have an error ? If so, why ? (Hint....
Question 7What would be the output of following code if ntpl = ("Hello", "Nita", "How's", "life ?") ?(a, b, c, d) = ntpl print("a is:", a) print("b...
Question 8What will be the output of the following code ?tuple_a = 'a', 'b' tuple_b = ('a', 'b') print (tuple_a == tuple_b)
Question 9What will be the output of the following code snippet ?rec = {"Name" : "Python", "Age" : "20", "Addr" : "NJ", "Country" : "USA"} id1 =...
Question 10Write the output of the code given below :my_dict = {"name" : "Aman", "age" : 26} my_dict['age'] = 27 my_dict['address'] = "Delhi"...
Question 11Write a method in python to display the elements of list thrice if it is a number and display the element terminated with '#' if it is not...
Question 12Name the function/method required to(i) check if a string contains only uppercase letters.(ii) gives the total length of the list.
Question 13What will be the output of the following code snippet ?my_dict = {} my_dict[(1,2,4)] = 8 my_dict[(4,2,1)] = 10 my_dict[(1,2)] = 12 sum =...
Question 1Write a program that prompts for a phone number of 10 digits and two dashes, with dashes after the area code and the next three numbers....
Question 2Write a program that should prompt the user to type some sentence(s) followed by "enter". It should then print the original sentence(s) and...
Question 3Write a program that takes any two lists L and M of the same size and adds their elements together to form a new list N whose elements are...
Question 4Write a program that rotates the elements of a list so that the element at the first index moves to the second index, the element in the...
Question 5Write a short python code segment that prints the longest word in a list of words.Solutionmy_list = eval(input("Enter the list : "))...
Question 6Write a program that creates a list of all the integers less than 100 that are multiples of 3 or 5.Solutiona = [] for i in range(0,100):...
Question 7Define two variables first and second so that first = "Jimmy" and second = "Johny". Write a short python code segment that swaps the values...
Question 8Write a python program that creates a tuple storing first 9 terms of Fibonacci series.Solutionlst = [0,1] a = 0 b = 1 c = 0 for i in...
Question 9Create a dictionary whose keys are month names and whose values are the number of days in the corresponding months.(a) Ask the user to...
Question 10Write a function called addDict(dict1, dict2) which computes the union of two dictionaries. It should return a new dictionary, with all...
Question 11Write a program to sort a dictionary's keys using Bubble sort and produce the sorted keys as a list.Solutionmy_dict = eval(input("Enter...
Question 12Write a program to sort a dictionary's values using Bubble sort and produce the sorted values as a list.Solutionmy_dict =...