🚀 Understanding the difference between `sort()` and `sorted()` can boost your Python coding efficiency! While `sort()` modifies the list in place, `sorted()` returns a new sorted list.
Example: Using sort()
numbers = [4, 2, 9, 1]
numbers.sort()
print(numbers) # Output: [1, 2, 4, 9]
Example: Using sorted()
numbers = [4, 2, 9, 1]
sorted_numbers = sorted(numbers)
print(sorted_numbers) # Output: [1, 2, 4, 9]
print(numbers) # Output: [4, 2, 9, 1]
Remember, `sort()` changes the original list while `sorted()` keeps it unchanged! Follow for more Python tips! 🐍✨"
#pythoninterview #learnpython #pythoninterviewquestions #pythonprogramming #pythondeveloper #coding #100daysofcoding #100secondsofcode #100daysofcode #csestack