CBSE Class 12 Computer Science Question 100 of 105

Python Revision Tour II — Question 7

Back to all questions
7
Question

Question 7

Define two variables first and second so that first = "Jimmy" and second = "Johny". Write a short python code segment that swaps the values assigned to these two variables and prints the results.

Solution
first = "Jimmy"
second = "Johny"
temp = first
first = second
second = temp
print("first =", first)
print("second =", second)
Output
first = Johny
second = Jimmy
Answer