[Type C]Q7. Define two variables first and second such that first=’Jimmy’ and second =’Johnny’. Write a short Python code segment that swaps the values assigned to these two variables and prints the results.

Program code:

Clear Doubts with Computer Tutor
In case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community: students.computertutor.in

Output:

Before Swapping Jimmy Johny 
After swapping: Johny Jimmy

In this program, we use the first variable to hold the value ‘Jimmy’ temporarily.

We then put the value of second which is ‘Johnny’ in first and later Jimmy in second.

In this way, the values get exchanged.

Basic python functionality is demonstrated in above program.

To view all the lessons in chapter 1: http://computertutor.in/class-12-computer-science/chapter-2/

To view entire class 12 computer science study material: http://computertutor.in/resources/

You cannot copy content of this page