Exercise: Swap Two Variables

  1. Write a program swap.py that exchanges (swaps) two variables var1 and var2, both str type.

    To output the values before and after the swap operation, use the print() function.

    var1 = 1
    var2 = 2
    
    print('Before:', var1, var2)
    # let the miracle happen: exchange the two variables!
    print('After:', var1, var2)
    

    Once the miracle took place, the output of the program should look like follows:

    $ python swap.py
    Before: 1 2
    After: 2 1
    

Dependencies

cluster_python Python Programming cluster_python_basics Python: The Language Fundamentals cluster_python_exercises Exercises cluster_python_exercises_herdt Exercises (External) python_basics_python_0130_syntax_etc Syntax etc. python_basics_python_0120_helloworld Hello World python_basics_python_0130_syntax_etc->python_basics_python_0120_helloworld python_basics_python_0160_boolean Boolean python_basics_python_0150_datatypes_overview Datatypes python_basics_python_0160_boolean->python_basics_python_0150_datatypes_overview python_basics_python_0110_blahblah Blahblah python_basics_python_0120_helloworld->python_basics_python_0110_blahblah python_basics_python_0140_variables Variables python_basics_python_0140_variables->python_basics_python_0130_syntax_etc python_basics_python_0150_datatypes_overview->python_basics_python_0140_variables python_exercises_herdt_swap Exercise: Swap Two Variables python_exercises_herdt_swap->python_basics_python_0120_helloworld python_exercises_herdt_swap->python_basics_python_0140_variables python_exercises_herdt_swap->python_basics_python_0150_datatypes_overview python_exercises_herdt_boolean Exercise: Boolean Expressions python_exercises_herdt_swap->python_exercises_herdt_boolean python_exercises_herdt_boolean->python_basics_python_0160_boolean