Q.Identify the invalid Python statement out of the following options:
(A) print("A",10,end="*")
(B) print("A",sep="*",10)
(C) print("A",10,sep="*")
(D) print("A"*10)
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →The invalid Python statement is print("A",sep="*",10) because a positional argument (10) cannot follow a keyword argument (sep="*") in a function call.
The print() function in Python is incredibly versatile, but it has specific rules about how you pass arguments to it. Understanding these rules, especially the distinction between positional and keyword arguments, is crucial for writing correct Python code.
When you call a function in Python, you can pass arguments in two main ways:
- Positional Arguments: These are arguments whose meaning is determined by their position in the function call. For example, in
print("Hello", "World"),"Hello"is the first item to print, and"World"is the second. - Keyword Arguments: These are arguments identified by a keyword (their parameter name) followed by an equals sign and a value. They are used to specify optional parameters like
sep(separator) andend(what to print at the end). For example,print("A", "B", sep="-")explicitly tellsprintto use a hyphen as a separator.
The fundamental rule for mixing these two types of arguments is that all positional arguments must come before any keyword arguments. If you place a positional argument after a keyword argument, Python will raise a SyntaxError.
Let's examine each option:
-
Option (A):
print("A",10,end="*")- Here,
"A"and10are positional arguments. end="*"is a keyword argument.- The keyword argument
end="*"correctly follows all positional arguments. - This statement is valid. It will print
A 10*(note the space between A and 10, which is the default separator).
- Here,
-
Option (B):
print("A",sep="*",10)- Here,
"A"is a positional argument. sep="*"is a keyword argument.10is another positional argument.- This statement attempts to place a positional argument (
10) after a keyword argument (sep="*"). This violates Python's syntax rules. - This statement is invalid. Python would raise a
SyntaxError: positional argument follows keyword argument. …
- Here,
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.