Output of Python program | Set 6 (Lists) Last Updated : 26 Apr, 2022 Comments Improve Suggest changes Like Article Like Report Prerequisite - Lists in Python Predict the output of the following Python programs. These question set will make you conversant with List Concepts in Python programming language. Program 1 Python list1 = ['physics', 'chemistry', 1997, 2000] list2 = [1, 2, 3, 4, 5, 6, 7 ] print "list1[0]: ", list1[0] #statement 1 print "list1[0]: ", list1[-2] #statement 2 print "list1[-2]: ", list1[1:] #statement 3 print "list2[1:5]: ", list2[1:5] #statement 4 Output:list1[0]: physics list1[0]: 1997 list1[-2]: ['chemistry', 1997, 2000] list2[1:5]: [2, 3, 4, 5]Explanation: To access values in lists, we use the square brackets for slicing along with the index or indices to obtain required value available at that index.For N items in a List MAX value of index will be N-1. Statement 1 : This will print item located at index 0 in Output. Statement 2 : This will print item located at index -2 i.e.second last element in Output. Statement 3 : This will print items located from index 1 to end of the list. Statement 4 : This will print items located from index 1 to 4 of the list.Program 2 Python list1 = ['physics', 'chemistry', 1997, 2000] print "list1[1][1]: ", list1[1][1] #statement 1 print "list1[1][-1]: ", list1[1][-1] #statement 2 Output:list1[1][1]: h list1[1][-1]: yExplanation: In python we can slice a list but we can also slice a element within list if it is a string. The declaration list[x][y] will mean that 'x' is the index of element within a list and 'y' is the index of entity within that string.Program 3 Python list1 = [1998, 2002, 1997, 2000] list2 = [2014, 2016, 1996, 2009] print "list1 + list 2 = : ", list1 + list2 #statement 1 print "list1 * 2 = : ", list1 * 2 #statement 2 Output:list1 + list 2 = : [1998, 2002, 1997, 2000, 2014, 2016, 1996, 2009] list1 * 2 = : [1998, 2002, 1997, 2000, 1998, 2002, 1997, 2000]Explanation: When addition(+) operator uses list as its operands then the two lists will get concatenated. And when a list id multiplied with a constant k>=0 then the same list is appended k times in the original list.Program 4 Python list1 = range(100, 110) #statement 1 print "index of element 105 is : ", list1.index(105) #statement 2 Output:index of element 105 is : 5Explanation: Statement 1 : will generate numbers from 100 to 110 and append all these numbers in the list. Statement 2 : will give the index value of 105 in the list list1.Program 5 Python list1 = [1, 2, 3, 4, 5] list2 = list1 list2[0] = 0; print "list1= : ", list1 #statement 2 Output:list1= : [0, 2, 3, 4, 5]Explanation: In this problem, we have provided a reference to the list1 with another name list2 but these two lists are same which have two references(list1 and list2). So any alteration with list2 will affect the original list. Comment More infoAdvertise with us Next Article Output of Python program | Set 6 (Lists) A Avinash Kumar Singh Improve Article Tags : Python Python-Output python-list Practice Tags : pythonpython-list Similar Reads Python Quiz These Python quiz questions are designed to help you become more familiar with Python and test your knowledge across various topics. From Python basics to advanced concepts, these topic-specific quizzes offer a comprehensive way to practice and assess your understanding of Python concepts. These Pyt 3 min read Python MCQ (Multiple Choice Questions) with Answers Python is a free open-source, high-level and general-purpose with a simple and clean syntax which makes it easy for developers to learn Python. Python programming language (latest Python 3) is being used in web development, Machine Learning applications, along with all cutting-edge technology in Sof 3 min read Output of Python Program | Set 1 Predict the output of following python programs: Program 1:Python r = lambda q: q * 2 s = lambda q: q * 3 x = 2 x = r(x) x = s(x) x = r(x) print (x) Output:24Explanation : In the above program r and s are lambda functions or anonymous functions and q is the argument to both of the functions. In firs 2 min read Output of python program | Set 2 Difficulty level : IntermediatePredict the output of following Python Programs. Program 1: Python3 class Acc: def __init__(self, id): self.id = id id = 555 acc = Acc(111) print (acc.id) Output: 111 Explanation: Instantiation of the class "Acc" automatically calls the method __init__ and passes the o 2 min read Output of Python Program | Set 3 Difficulty level : Intermediate Predict the output of following Python Programs. Program 1: Python3 class Geeks: def __init__(self, id): self.id = id manager = Geeks(100) manager.__dict__['life'] = 49 print (manager.life + len(manager.__dict__)) Output:51 Explanation : In the above program we are cr 2 min read Output of Python Program | Set 4 Difficulty level : Intermediate Predict the output of the following Python Programs. Program 1: Python nameList = ['Harsh', 'Pratik', 'Bob', 'Dhruv'] print nameList[1][-1] Output: k Explanation: The index position -1 represents either the last element in a list or the last character in a String. In 2 min read Output of Python program | Set 5 Predict the output of the following programs: Program 1: Python def gfgFunction(): "Geeksforgeeks is cool website for boosting up technical skills" return 1 print (gfgFunction.__doc__[17:21]) Output:coolExplanation: There is a docstring defined for this method, by putting a string 3 min read Output of Python program | Set 6 (Lists) Prerequisite - Lists in Python Predict the output of the following Python programs. These question set will make you conversant with List Concepts in Python programming language. Program 1 Python list1 = ['physics', 'chemistry', 1997, 2000] list2 = [1, 2, 3, 4, 5, 6, 7 ] print "list1[0]: 3 min read Output of Python programs | Set 7 Prerequisite - Strings in Python Predict the output of the following Python programs. These question set will make you conversant with String Concepts in Python programming language. Program 1Python var1 = 'Hello Geeks!' var2 = "GeeksforGeeks" print "var1[0]: ", var1[0] # statement 1 print "var2[1:5 3 min read Output of Python programs | Set 8 Prerequisite - Lists in Python Predict the output of the following Python programs. Program 1 Python list = [1, 2, 3, None, (1, 2, 3, 4, 5), ['Geeks', 'for', 'Geeks']] print len(list) Output: 6Explanation: The beauty of python list datatype is that within a list, a programmer can nest another list, 3 min read Like