Computer Science
Is a string the same as a tuple of characters?
Python Tuples
1 Like
Answer
No, a string and a tuple of characters are not the same even though they share similar properties like immutability, concatenation, replication, etc.
A few differences between them are as follows:
1. in
operator works differently in both of them. Below example shows this difference. Example:
my_string = "Hello"
my_tuple = ('h','e','l','l','o')
print("el" in my_string)
print("el" in my_tuple)
Output
True
False
2. Certain functions like split( ), capitalize( ), title( ), strip( ), etc. are present only in string and not available in tuple object.
Answered By
1 Like