sorted() is a general-purpose function that can be used with any iterable, including strings, and it returns a new sorted list. sort() is a method specifically for lists, and it sorts the elements of the list in-place. When dealing with strings, you need to convert them to a list to use sort() and then join the characters back together if needed.
#"python".sort()#AttributeError: 'str' object has no attribute 'sort'
print(sorted("python"))
Ans is B,D
#rfind("python","r")#NameError: name 'rfind' is not defined
"python".index("th")
Ans is A,D
#"python".sort()#AttributeError: 'str' object has no attribute 'sort'
print(sorted("python"))
#rfind("python","r")#NameError: name 'rfind' is not defined
"python".index("th")
Ans is A,D
Question 86
Which of the following invocations are valid? (Choose two.)
respuesta ok B y D
A. "python".sort()
B. sorted("python")
C. rfind("python","r")
D. "python".index("th")
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
andr3
Highly Voted 1 year, 8 months agovlobachevsky
Highly Voted 3 years, 1 month agoDamon54
Most Recent 9 months, 3 weeks agoDamon54
9 months, 3 weeks agozantrz
10 months agoseaverick
10 months agoseaverick
10 months agodcross
1 year agoJnanada
2 years, 3 months agostuartz
2 years, 5 months agomacxsz
2 years, 6 months agoNoarmy315
2 years, 10 months agoDTL001
2 years, 11 months ago