एक स्ट्रिंग s="Welcome" दी गई है, निम्नलिखित में से कौन सा कोड गलत है?
Given a string s="Welcome", which of the following code is incorrect ?
A
print s[0]
B
print s.lower()
C
s[1]='r'
D
print s.strip()
Explanation
Here’s a quick breakdown:
- (A)
s[0]is correct; it prints the first character"W". - (B)
s.lower()is correct; it converts the string to"welcome". - (C)
s[1] = 'r'is incorrect because strings are immutable in Python (you can't change individual characters). - (D)
s.strip()is correct; it removes any leading or trailing spaces (if any).
Answer:
(C) s[1] = 'r' is incorrect.
-
-
पायथन में स्ट्रिंग्स Immutable (अपरिवर्तनीय) होती हैं। आप किसी स्ट्रिंग के एक विशिष्ट कैरेक्टर को असाइनमेंट के ज़रिए नहीं बदल सकते।
-
Correct Answer: C) s[1]='r'