Explore topic-wise MCQs in Python.

This section includes 176 Mcqs, each offering curated multiple-choice questions to sharpen your Python knowledge and support exam preparation. Choose a topic below to get started.

51.

___ function is used for joining lists.

A. foreach
B. for
C. split
D. join
Answer» E.
52.

___ is known as range operator.

A. . .
B. $1
C. $.
D. $_
Answer» B. $1
53.

The command @x=(1. .10) will assign first ten integer values to the array ‘a’.

A. True
B. False
C. May be
D. Can't say
Answer» B. False
54.

For deleting the elements from the right of the array ___ function is used.

A. pop
B. push
C. queue
D. shift
Answer» B. push
55.

Which function can combine the functionalities of push, pop, unshift and shift?

A. splice
B. add
C. delete
D. split
Answer» B. add
56.

To add elements to the right side of the array ____ function is used.

A. pop
B. push
C. queue
D. unshift
Answer» C. queue
57.

File x .c has 5 lines of code. The commanddate l tee abc l sort - x. c l wc -1, displays

A. 5
B. 6
C. 0
D. an error message
Answer» C. 0
58.

For looping in a list, ____ is used.

A. for
B. fordo
C. foreach
D. while
Answer» B. fordo
59.

awk doesn’t use $ in evaluation or assignment of variables.

A. True
B. False
C. may be
D. Can't say
Answer» B. False
60.

Which option is used for storing awk programs in a file?

A. -e
B. -f
C. -i
D. -h
Answer» B. -f
61.

awk supports the use of arrays.

A. True
B. False
C. May be
D. Can't say
Answer» B. False
62.

Which of the following is not true about awk arrays?

A. they are not expanded automatically
B. they are initialized to zero or an empty string
C. index can be a string also
D. they are not formally defined
Answer» B. they are initialized to zero or an empty string
63.

Which function is used by perl for displaying the length of a string?

A. string
B. len
C. split
D. length
Answer» E.
64.

___ function returns the first occurrence of a character in a string.

A. string
B. index
C. split
D. length
Answer» C. split
65.

We cannot perform sorting on columns using sort command.

A. True
B. False
C. May be
D. Can't say
Answer» C. May be
66.

Context switch changes the process mode from

A. user to kernel mode
B. kernel to user mode
C. kernel mode to the kernel process
D. Both (a) and (b)
Answer» E.
67.

awk uses _____ dimensional arrays.

A. one
B. two
C. multi
D. three
Answer» B. two
68.

The ___ prefix to an array name signifies the last index of the array.

A. $0
B. $#
C. #$
D. $_
Answer» C. #$
69.

Which of the following is referred to as default variable?

A. $0
B. $1
C. $!
D. $_
Answer» E.
70.

A user-defined variable is initialized to ____

A. zero
B. zero or null string
C.
D. operator
Answer» C.
71.

___ operator is used for selecting current line number.

A. $0
B. $1
C. $.
D. $_
Answer» B. $1
72.

The printf function uses ___ for string data and ___ for numeric.

A. %f, %l
B. %s, %f
C. %s, %d
D. %s, %s
Answer» D. %s, %s
73.

head -n 3 emp.lst | tr ‘[a-z]’ ‘[A-Z]’Above command will change the case of text from lower to upper.

A. True
B. False
C. May be
D. Can't say
Answer» B. False
74.

______ option is used for compressing multiple consecutive characters.

A. -d
B. -c
C. -n
D. -s
Answer» E.
75.

The output of the following command will be:$ uniq foo1 foo2

A. erroneous
B. output stored in foo2
C. concatenates both files
D. process foo1 and output is stored in foo2
Answer» E.
76.

To perform context addressing, we have to enclose the pattern in ____

A. double quotes
B. single quotes
C. / /
D. $ $
Answer» D. $ $
77.

The following command will match the lines beginning with ‘2’.$ grep “^2” emp.lst

A. True
B. False
C. May be
D. Can't say
Answer» B. False
78.

The following command will match ‘Agarwal’, ‘agarwal’ and ‘agrawal’.$ grep “[aA]g[ar][ar]wal” emp.lst

A. True
B. False
C. May be
D. Can't say
Answer» B. False
79.

If there are special characters in a pattern, then we’ve to enclose them in ______

A. single quotes
B. double quotes
C. without any quotes
D. all quotes
Answer» C. without any quotes
80.

perl is ____ of grep, tr, sed and awk.

A. subset
B. superset
C. child
D. parent
Answer» C. child
81.

Which of the following will be used to print lines containing ‘manager’ in emp.lst?

A. awk ‘/manager/ { print }’ emp.lst
B. awk ‘/manager { print }’ emp.lst
C. awk ‘/manager/ { print } emp.lst
D. awk ‘manager { print }’ emp.lst
Answer» B. awk ‘/manager { print }’ emp.lst
82.

For deleting the elements from the left of the array ___ function is used.

A. pop
B. push
C. queue
D. shift
Answer» E.
83.

To repeat a string, perl uses ___ operator.

A. /
B. .
C. x
D. \\
Answer» D. \\
84.

____ function breaks up a string on the basis of delimiter.

A. length
B. substr
C. system
D. split
Answer» E.
85.

Which of the following are concatenation operators?

A. /
B. .
C. _
D. \\
Answer» E.
86.

The command $ sed -n ‘$p’ emp.lst will display the last line.

A. True
B. False
C. May be
D. Can't say
Answer» B. False
87.

Which of the following is an associative array?

A. a[ ]
B. arr[ ]
C. envr [ ]
D. ENVIRON[ ]
Answer» E.
88.

We can specify filenames in command line using perl.

A. True
B. False
C. May be
D. Can't say
Answer» B. False
89.

The following will display :perl -e ‘print “UNIX” x 10 . “\n” ;’

A. UNIX
B. UNIX 10 times
C. error message
D. \n
Answer» C. error message
90.

____ section can be used if we’ve to print something after processing the last line.

A. end
B. begin
C. start
D. first
Answer» C. start
91.

Perl also supports use of for loop in the following manner.for($i=0;$i<3;$i++){ }

A. True
B. False
C. May be
D. Can't say
Answer» B. False
92.

awk uses ___ operator for concatenating strings.

A. >
B. |
C. *
D. no operator available
Answer» E.
93.

To add elements to the left side of the array ____ function is used.

A. pop
B. push
C. queue
D. unshift
Answer» E.
94.

sqroot(x) function returns the square root of x.

A. True
B. False
C. May be
D. Can't say
Answer» C. May be
95.

____ section can be used if we’ve to print something before processing the first line.

A. end
B. begin
C. start
D. first
Answer» C. start
96.

The following command will produce an error.$ cut -d “|” -f 1,4 emp.lst

A. True
B. False
C. May be
D. Can't say
Answer» C. May be
97.

Which one of the following commands is incorrect?

A. $ cut -d “|” -f 1,4 emp.lst
B. $ cut -c -3 emp.lst
C. $ tail -c -511 foo
D. $ tail -c 500 foo
Answer» E.
98.

Which function is identical to Strstr ( )?

A. Strlen ( )
B. Strchar ( )
C. Strcmp ( )
D. None of them
Answer» C. Strcmp ( )
99.

Process of breaking up a long string into words is called as

A. Stroking
B. Delimiters
C. Tokenizing
D. Parsing
Answer» D. Parsing
100.

Case functions are used for

A. Changing lowercase to uppercase
B. Changing the length of string
C. String replacement functions
D. Searching functions
Answer» B. Changing the length of string