Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

unpack tuple python

def myFunc(word1="", word2=""):
	return word1+" "+word2
# passes tuple elements as separate arguments
print(myFunc(*("hello","world"))) # or
print(myFunc(*("oneArgument",))) # , to imply its an interable
Comment

Tuples unpacking

>>> b = ("Bob", 19, "CS")
>>> (name, age, studies) = b    # tuple unpacking
>>> name
'Bob'
>>> age
19
>>> studies
'CS'
Comment

tuple unpacking in 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)
Comment

unpacking tuples in python

>>> def f():
    return 1,2
>>> a,b=f()
>>> a
1
>>> b
2
Comment

unpacking of tuples in python

tuple1 = ("python","c#","c++")
(programming_language_1,programming_language_2,programming_language_3) = tuple1
print(programming_language_1, "
",programming_language_2,"
",programming_language_3)
Comment

tuple unpacking

odd_numbers = (1, 3, 5)
even_numbers = (2, 4, 6)
Code language: Python (python)
Comment

tuple unpacking

count, fruit, price = (2, 'apple', 3.5)
Comment

PREVIOUS NEXT
Code Example
Python :: how to start a working to run a particular queue 
Python :: numpy array majority and how many 
Python :: Get Project Parameter Dynamo Revit 
Python :: pep8 E302 
Python :: countvectorizer remove stop words 
Python :: Brainf**k Interpreter in Python 
Python :: Loop per n (batch) 
Python :: pygame.k_kp_enter 
Python :: what does it mean when i get a permission error in python 
Python :: featch detail of subscription in stripe api 
Python :: how to make an infinite loop in python 
Python :: histogram plot seaborn 
Python :: python quick sort 
Python :: how to create a login page in python 
Python :: python list three from the back 
Python :: pandas 3d tutorail pythoin 
Python :: omr sheet python stackoverflow 
Python :: platform.system() return value 
Python :: pasar tupla a funcion python 
Python :: random ordered slice of an array 
Python :: telephone number word generator python 
Python :: python filter dictionary 
Python :: geopandas nan to 0 
Python :: Minimum Number of Operations to Move All Balls to Each Box in python used in function method 
Python :: the code panda 
Python :: pristine 
Python :: how to install python on visual studio code 
Python :: python pass function as argument 
Python :: using progress bar with rich python 
Python :: pandas groupby and keep columns 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =