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.

1.

The formatting method {1:

Answer»

Correct answer is (b) second, left

Explanation: The formatting method {1:<10} represents the second POSITIONAL ARGUMENT, left justified in a 10 CHARACTER wide field.

2.

The output of which of the codes shown below will be: “There are 4 blue birds.”?(a) ‘There are %g %d birds.’ %4 %blue(b) ‘There are %d %s birds.’ %(4, blue)(c) ‘There are %s %d birds.’ %[4, blue](d) ‘There are %d %s birds.’ 4, blueThe question was posed to me by my school teacher while I was bunking the class.I would like to ask this question from Formatting in division Formatting & Decorators of Python

Answer»

Correct answer is (B) ‘There are %d %s birds.’ %(4, blue)

Easy explanation - The code ‘There are %d %s birds.’ %(4, blue) results in the output: There are 4 blue birds. When we INSERT more than one value, we should group the VALUES on the RIGHT in a tuple.

3.

Which of the following formatting options can be used in order to add ‘n’ blank spaces after a given string ‘S’?(a) print(“-ns”%S)(b) print(“-ns”%S)(c) print(“%ns”%S)(d) print(“%-ns”%S)This question was addressed to me in a national level competition.This key question is from Formatting topic in portion Formatting & Decorators of Python

Answer» RIGHT answer is (d) print(“%-ns”%S)

For explanation: In order to ADD ‘n’ blank spaces after a given STRING ‘S’, we use the FORMATTING option:(“%-ns”%S).