Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

variable swapping python

#tuple unpacking
myTuple = ("Tim","9","Smith")
#tuple unpacking allows us to store each tuple element in a variable
#syntax - vars = tuple
"""NOTE: no of vars must equal no of elements in tuple"""
name,age,sirname = myTuple
print(name)
print(age)
print(sirname)
#extra
#this alows us to easily switch values of variables
name,sirname = sirname,name
print(name)
print(sirname)
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #variable #swapping #python
ADD COMMENT
Topic
Name
1+8 =