# Python/Python Mcq Set 7 Sample Test,Sample questions

## Question: ` Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is:`

1. [0, 1, 2, 3]

2. [0, 1, 2, 3, 4]

3.[0.0, 0.5, 1.0, 1.5]

4.[0.0, 0.5, 1.0, 1.5, 2.0]

1. 3

2. 5

3.25

4. 1

1. 5

2.4

3.None

4. Error

## Question: ` To insert 5 to the third position in list1, we use which command?`

1. list1.insert(3, 5)

2. list1.insert(2, 5)

4. list1.append(3, 5)

## Question: ``` What will be the output of the following Python code snippet? print('ab cd ef'.splitlines())```

1. [‘ab’, ‘cd’, ‘ef’]

2. [‘ab ’, ‘cd ’, ‘ef ’]

3.[‘ab ’, ‘cd ’, ‘ef’]

4. [‘ab’, ‘cd’, ‘ef ’]

## Question: ``` What will be the output of the following Python code snippet? print('abcdef12'.replace('cd', '12'))```

1.ab12ef12

2.abcdef12

3. ab12efcd

4.none of the mentioned

## Question: ``` What will be the output of the following Python code snippet? print('abef'.replace('cd', '12'))```

1.abef

2.12

3.error

4.none of the mentioned

1.A

2.Daman

3.Error

4. n

## Question: ``` What will be the output of the following Python code? print('cba'.maketrans('abc', '123'))```

1.{97: 49, 98: 50, 99: 51}

2.{65: 49, 66: 50, 67: 51}

3.321

4.123

## Question: ` Which of the following commands will create a list?`

1. list1 = list()

2. list1 = list()

3. list1 = list([1, 2, 3])

4.all of the mentioned

## Question: `Suppose list1 is [1, 3, 2], What is list1 * 2?`

1.[2, 6, 4]

2. [1, 3, 2, 1, 3]

3.[1, 3, 2, 1, 3, 2]

4. [1, 3, 2, 3, 2, 1]

1.1

2.9

3.15

4. Error

1.Error

2.None

3.25

4.2

## Question: `Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?`

1. [2, 33, 222, 14]

2. Error

3.25

4. [25, 14, 222, 33, 2]

1. 2445

2. 133

3.12454

4.123

## Question: `Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.reverse()?`

1. [3, 4, 5, 20, 5, 25, 1, 3]

2.[1, 3, 3, 4, 5, 5, 20, 25]

3.[25, 20, 5, 5, 4, 3, 3, 1]

4. [3, 1, 25, 5, 20, 5, 4, 3]

1.0

2.4

3.1

4.2

1.0

2.1

3.4

4.2

## Question: `Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the following is correct syntax for slicing operation?`

1. print(list1[0])

2. print(list1[:2])

3. print(list1[:-2])

4.all of the mentioned

## Question: `Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.extend([34, 5])?`

1.[3, 4, 5, 20, 5, 25, 1, 3, 34, 5]

2.[1, 3, 3, 4, 5, 5, 20, 25, 34, 5]

3. [25, 20, 5, 5, 4, 3, 3, 1, 34, 5]

4.[1, 3, 4, 5, 20, 5, 25, 3, 34, 5]

## Question: `Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.pop(1)?`

1.[3, 4, 5, 20, 5, 25, 1, 3]

2.[1, 3, 3, 4, 5, 5, 20, 25]

3.[3, 5, 20, 5, 25, 1, 3]

4.[1, 3, 4, 5, 20, 5, 25]

## Question: `To add a new element to a list we use which command?`

2.list1.append(5)

## Question: `To remove string “hello” from list1, we use which command?`

1. list1.remove(“hello”)

2. list1.remove(“hello”)

3.list1.removeAll(“hello”)

4. list1.removeOne(“hello”)

## Question: `To shuffle the list(say list1) what function do we use?`

1. list1.shuffle()

2. shuffle(list1)

3. random.shuffle(list1)

4. random.shuffleList(list1)

## Question: `What is the output when we execute list(“hello”)?`

1.[‘h’, ‘e’, ‘l’, ‘l’, ‘o’]

2. [‘hello’]

3. [‘llo’]

4. [‘olleh’]

## Question: ```What will be the output of the following Python code snippet? print('ab cd ef'.title())```

1.Ab cd ef

2.Ab cd eF

3.Ab Cd Ef

4.none of the mentioned

## Question: ```What will be the output of the following Python code snippet? print('ab cd-ef'.title())```

1.Ab cd-ef

2. Ab Cd-ef

3.Ab Cd-Ef

4.none of the mentioned

1. AB!@

2. ab12

3.aB!2

4.aB1@

1.bcde

2.abcd

3.error

4.bcdd

## Question: ```What will be the output of the following Python code snippet? print('abcdefcdghcd'.split('cd'))```

1. [‘ab’, ‘ef’, ‘gh’]

2.[‘ab’, ‘ef’, ‘gh’, ”]

3.(‘ab’, ‘ef’, ‘gh’)

4.(‘ab’, ‘ef’, ‘gh’, ”)

## Question: ```What will be the output of the following Python code snippet? print('abcdefcdghcd'.split('cd', -1))```

1. [‘ab’, ‘ef’, ‘gh’]

2.[‘ab’, ‘ef’, ‘gh’, ”]

3.(‘ab’, ‘ef’, ‘gh’)

4.(‘ab’, ‘ef’, ‘gh’, ”)

## Question: ```What will be the output of the following Python code snippet? print('abcdefcdghcd'.split('cd', 0))```

1. [‘abcdefcdghcd’]

2.‘abcdefcdghcd’

3. error

4.none of the mentioned

## Question: ```What will be the output of the following Python code snippet? print('abcdefcdghcd'.split('cd', 2))```

1. [‘ab’, ‘ef’, ‘ghcd’]

2. [‘ab’, ‘efcdghcd’]

3. [‘abcdef’, ‘ghcd’]

4.none of the mentioned

1.ab1ef2

2.abcefd

3.ab1efd

4. ab12ed2

## Question: ```What will be the output of the following Python code snippet? print('abef'.partition('cd'))```

1.(‘abef’)

2.(‘abef’, ‘cd’, ”)

3. (‘abef’, ”, ”)

4.error

1.(‘cd’)

2.(”)

3.(‘cd’, ”, ”)

4.(”, ‘cd’, ”)

1. True

2.False

3.None

4.Error

1. xyyxyyxyxyxxy

2.12y12y1212x12

3.12yxyyxyxyxxy

4.xyyxyyxyxyx12

## Question: ```What will be the output of the following Python code snippet? print('xyyxyyxyxyxxy'.replace('xy', '12', 100))```

1.xyyxyyxyxyxxy

2.12y12y1212x12

3. none of the mentioned

4.error

1. True

2.False

3.Error

4.None

## Question: ```What will be the output of the following Python code? print(''' foo'''.lstrip())```

1. foo

2.foo

3. foo

4.none of the mentioned

## Question: ```What will be the output of the following Python code? print(''' foo'''.lstrip())```

1. foo

2.foo

3. foo

4.none of the mentioned

1. n

2.1rn@

3.rn

4.r

## Question: ```What will be the output of the following Python code? print('a'.maketrans('ABC', '123'))```

1.{97: 49, 98: 50, 99: 51}

2.{65: 49, 66: 50, 67: 51}

3.{97: 49}

4.1

## Question: ```What will be the output of the following Python code? print('abcd'.partition('cd'))```

1. (‘ab’, ‘cd’, ”)

2.(‘ab’, ‘cd’)

3.error

4.none of the mentioned

## Question: ```What will be the output of the following Python code? print('abcdef'.partition('cd'))```

1. (‘ab’, ‘ef’)

2.(‘abef’)

3.(‘ab’, ‘cd’, ‘ef’)

4.2

## Question: ```What will be the output of the following Python code? print('abcdefcdgh'.partition('cd'))```

1.(‘ab’, ‘cd’, ‘ef’, ‘cd’, ‘gh’)

2.(‘ab’, ‘cd’, ‘efcdgh’)

3. (‘abcdef’, ‘cd’, ‘gh’)

4.error

1. True

2. False

3. None

4.error

## Question: ```What will be the output of the following Python code? print('xyxxyyzxxy'.lstrip('xyy'))```

1.zxxy

2.xyxxyyzxxy

3.xyxzxxy

4.none of the mentioned

1.error

2. zxxyxyy

3.z

4.zxxy

## More MCQS

##### R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!