Explore topic-wise InterviewSolutions in .

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

118901.

What is a preprocessor directive?

Answer»

A preprocessor directive is a command that is considered for execution before the processor executes the program.

118902.

Explain the use of explicit conversion with an example.

Answer»

This is also called as typecasting. It temporarily changes a variable data type from its declared data type to a new one.

For example, T_Pay = double (salary) + bonus;

118903.

निम्न में से कौन-सा फंक्शन हैडर फाइल stdlib.h में पाया जाता है?(a) feof(b) abs(c) strch(d) cgets

Answer»

सही विकल्प है (d) cgets

118904.

Mention the types of typecasting.

Answer»

The two types of typecasting are implicit conversion and explicit conversion.

118905.

Strings which contains double quotes should be defined with …….. quotes(a) Single(b) Double(c) Triple(d) All the these

Answer»

Strings which contains double quotes should be defined with Triple quotes

118906.

Write a short about the followings with suitable example?

Answer»
SyntaxDescriptionExample
CapitalizeUsed to capitalize the first character of the string>>> city = "chennai"
>>>print(city.capitalize())Chennai
swap caseIt will change case of every character to its opposite case vice-versa.>>>strI = "tAmiLNaDu"
>>>print(strI.swapcase())TamllnAdU
118907.

In strings, the negative index assigned from the last character to the first character in reverse order begins with (a) 0(b) 1(c) -1(d) -2

Answer»

In strings, the negative index assigned from the last character to the first character in reverse order begins with -1

118908.

What is the use of format( )? Give an example?

Answer»

The format( ) function used with strings is very versatile and powerful function used for formatting strings. The curly braces { } are used as placeholders or replacement fields which get replaced along with format( ) function.

Example:

num1 = int (input (“Number 1: “))

num2 = int (input (“Number 2: “))

print (“The sum of { } and { } is { }”.format (num1, num2, (num1 + num2)))

OutPut:

Number 1 : 34

Number 2 : 54

The sum of 34 and 54 is 88.

118909.

Mention any two functions of stdio.h

Answer»

Printf() and scanf() are two functions of stdio.h

118910.

Mention any two functions of stdlib.h

Answer»

Atoi() and itoa() are two functions for stdlib.h

118911.

What is the use of iostream.h in C++?

Answer»

iostream stands for input/output stream. It is a header file which we include in our programs, to perform basic input-output operations.

118912.

Mention any two string.h functions.

Answer»

Strupr() and strlwr()

118913.

Which is used to display a string multiple number of times?(a) Repeating(b) *(c) Multiplication operator(d) All the above

Answer»

(d) All the above

118914.

Mention any two ctype.h functions.

Answer»

Toupper() and tolower() are the two examples for ctype.h functions.

118915.

Which command is used to remove the entire string variable?(a) Remove(b) Del(c) Delete(d) Strike

Answer»

Del is used to remove the entire string variable

118916.

Which of the following is used as placeholders or replacement fields which get replaced along with format ( ) function?(a) { }(b) <>(c) ++(d) ^^

Answer»

Answer is (a) { } 

118917.

Defining strings within triple quotes allows creating: (a) Single line Strings(b) Multiline Strings(c) Double line Strings(d) Multiple Strings

Answer»

(b) Multiline Strings

118918.

Write a Python program to display the given pattern?C O M P U T E RC O M P U T EC O M P U TC O M P UC O M PC O MC OC

Answer»

Program:

str1 = “COMPUTER”

index = len (str1)

for i in str 1:

print (str 1[: index])

index – = 1

118919.

Which function is used to change all occurrences of a particular character in a string?(a) Replace ( )(b) Change ( )(c) Edit ( )(d) Append ( )

Answer»

(a) Replace ( )

118920.

The subscript of a string may be:(a) Positive(b) Negative(c) Both(a) and (b)(d) Either (a) or (b)

Answer»

(d) Either (a) or (b)

118921.

What will be the output of the following python code?

Answer»

str1 = “School”

print (str1*3)

Output:

School School School

118922.

In python, end value is considered as ……(a) 0(b) n(c) n – 1(d) 1

Answer»

In python, end value is considered as n – 1

118923.

……. is a substring of a main string.

Answer»

Slice is a substring of a main string

118924.

The default value of stride is ……(a) 0(b) 1(c) n(d) n – 1

Answer»

The default value of stride is 1

118925.

Which of the following is the output of the following python code?str1= ”TamilNadu”print (str1 [:: -1])(a) Tamilnadu(b) Tmlau(c) UdanlimaT(d) UdaNlimaT

Answer»

(c) UdanlimaT

118926.

Which of the following operator is used for concatenation?(a) +(b) &(c) *(d) =

Answer»

+ operator is used for concatenation

118927.

What is String?

Answer»

String is a data type in python, which is used to handle array of characters. String is a sequence of Unicode characters that may be a combination of letters, numbers, or special symbols enclosed within single, double or even triple quotes.

Example:

‘Welcome to learning Python’

“Welcome to learning Python”

“Welcome to learning Python”

118928.

Find the wrong statement from the following.(I) Slice a single character from a string (II) Slice a substring(III) Slice a substring without specifying beginning index(IV) Slice a substring without specifying end index (a) (I), (II)(b) (II), (III), (IV)(c) All are wrong(d) All are correct

Answer»

(d) All are correct

118929.

Write a program to print integers with ‘*’ on the right of specified width?

Answer»

x = 1 2 3

print (“original number: “ , x)

print (“formatted number(right padding, width 6): “+” {: * < 7 d}”.format(x));

Output:

original number : 1 2 3

formatted number (right padding, width 6): 1 2 3 ***

118930.

What will be the output of the following code?str1= “Chennai Schools”str1[7] = “_”(a) Chennai – Schools(b) Chenna – School(c) Type error(d) Chennai

Answer»

(c) Type error

118931.

What will be the output of the given python program? str1 = “welcome”str2 = “to school”str3 = str1[: 2] str2[len(str2)-2:]print (str3)

Answer»

output:

weoo 1

118932.

The positive subscript of the string starts from …….. and ends with ……

Answer»

The positive subscript of the string starts from 0 and ends with n – 1

118933.

Find the wrongly matched pair from the following.(a) Append ⇒ + =(b) Concate ⇒ +(c) Repeat ⇒ /(d) Slice ⇒ [ ]

Answer»

(c) Repeat ⇒ /

118934.

Do you modify a string in Python?

Answer»

If you want to modify the string, a new string value can be assign to the existing string variable. To define a new string value to the existing string variable. Python completely overwrite new string on the existing string.

Example:

>>> str1= ”How are you”

>>> print (str1)

How are you

>>> str1= ”How about you”

>>> print (str1)

How about you

118935.

Find the wrong match(a) Backslash – \b(b) Backslash – //(c) Carriage return – \r(d) Line feed – \n

Answer»

(b) Backslash – //

118936.

…….. is the formatting character for short numbers in floating point or exponential notation.

Answer»

% g or % G is the formatting character for short numbers in floating point or exponential notation.

118937.

Write a program to add a prefix text to all the lines in a string?

Answer»

import

text =

“‘Strings are immutable. Slice is a substring of a main string. Stride is a third argument in slicing operation'”

text_without_lndentation= textwrap.dedent (text) wrapped = extwrap.fill (text_without_Indentation, width = 50)

print (textwrap.indent(wrapped, ‘*’)

print ()

Output:

  • Strings are immutable.
  • Slice is a substring of a main string.
  • Stride is a third argument in slicing operation
118938.

……. is the formatting character for signed decimal integer. (a) %d or %i(b) %d and %i(c) %d %u (d) %i &amp;u

Answer»

(a) %d or %i

118939.

……. function is a powerful function used for formatting strings.

Answer»

Format ( ) function is a powerful function used for formatting strings.

118940.

Which operator is used to append a new string with an existing string?(a) +(b) + =(c) *(d) * =

Answer»

+ = is used to append a new string with an existing string

118941.

Write a program to append a string to another string without using + = operator?

Answer»

s1 = input (“Enter the first string: “)

s2 = input (“Enter the second string: “)

print (‘concatenated strings = ’ , ” ” ,join ([s1, s2])) 

Output:

Enter the first string: Tamil

Enter the second string: Nadu

concatenated strings = Tamil Nadu

118942.

The ……. and ……. operators can be used with strings to determine whether a string is present another string.

Answer»

The in and Not in operators can be used with strings to determine whether a string is present another string.

118943.

Which of the following is the slicing operator?(a) { }(b) [ ](c) &lt;&gt;(d) ( )

Answer»

[ ] is the slicing operator

118944.

Escape sequences starts with a ………

Answer»

Escape sequences starts with a Back Slash

118945.

Find the output?Programstr1 = ‘ * ‘i=1while i&lt;=5: print (str1*i)i+=1

Answer»

Output :

*

* *

* * *

* * * *

* * * * *

118946.

Explain about string operators in python with suitable example?

Answer»

String Operators:

Python provides the following operators for string operations. These operators are useful to manipulate string.

(i) Concatenation (+):

Joining of two or more strings is called as Concatenation. The plus (+) operator is used to concatenate strings in python. 

Example:

>>> “welcome” + “Python”

‘welcomePython’

(ii) Append (+=):

Adding more strings at the end of an existing string is known as append. The operator += is used to append a new string with an existing string. 

Example:

>>> str1 = ”Welcome to ”

>>> str1+= ”Leam Python”

>>> print (str1)

Welcome to Learn Python

(iii) Repeating (*):

The multiplication operator (*) is used to display a string in multiple number of times.

Example:

>>> str1 = ”Welcome”

>>> print (str1*4)

Welcome Welcome Welcome Welcome

(iv) String slicing:

Slice is a substring of a main string. A substring can be taken from the original string by using [ ] operator and index or subscript values. Thus, [ ] is also known as slicing operator. Using slice operator, you have to slice one or more substrings from a main string.

General format of slice operation:

str[start: end]

Where start is the beginning index and end is the last index value of a character in the string. Python takes the end value less than one from the actual index specified.

For example, if you want to slice first 4 characters from a string, you have to specify it as 0 to 5. Because, python consider only the end value as n – 1.

Example:

(i) slice a single character from a string 

>>> str1= ”THIRUKKURAL ”

>>> print (str1 [0])

T .

(v) Stride when slicing string

When the slicing operation, you can specify a third argument as the stride, which refers to the number of characters to move forward after the first character is retrieved from the string. The default value of stride is 1.

Example:

>>> str1= “Welcome to learn Python”

>>> print (str1 [10:16])

learn

Note: Remember that, python takes the last value as n – 1

You can also use negative value as stride (third argument). If you specify a negative value, it prints in reverse order.

Example:

>>> str1 = “Welcome to learn Python”

>>> print(str1 [::-2])

nhy re teoIW

118947.

………. is the membership operator.(a) is(b) at(c) to(d) in

Answer»

in is the membership operator.

118948.

Give any 6 formatting characters with their usage? Formatting characters

Answer»
Format charactersUSAGE
% ccharacters
% d (or) %iSigned decimal integer
% sString
% uUnsigned decimal integer
% oOctal integer
%x or %XHexadecimal integer (lower case x refers a-f; upper case X refersA-F)
118949.

Write a program to count the number of characters, words and lines in a given string?

Answer»

string = input (“Enter string:”)

char = 0

word = 0

line = 0

for i in string:

char = char + 1

if (i = = “):

word = word + 1

elif (i = = ‘ \n’):

line = line +1

print (“Number of words in the string: “)

print (word)

print (“Number of characters in the string: “)

print (char)

print (“Number of lines in the string: “)

print (line)

Output:

Enter string: welcome to learning python

Number of words in the string : 4

Number of characters in the string : 26

Number of lines in the string : 1

118950.

How many membership operators are there?(a) 2(b) 3(c) 4(d) 5

Answer»

There are 2 membership operators