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

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 :: Make A Snake Game Using Python and Pygame 
Python :: python compare if 2 files are equal 
Python :: fiel to base64 python 
Python :: codeforces 677a python solution 
Python :: pandas replace nan 
Python :: python initialize dictionary with lists 
Python :: pandas unnamed zero 
Python :: how to make python speak 
Python :: df.shape 0 
Python :: how to parse dicts in reqparse in flask 
Python :: minute range python 
Python :: series to dataframe with column names 
Python :: playsound moudle python 
Python :: main arguments python 
Python :: rename columns in datarame pandas 
Python :: Finding the Variance and Standard Deviation of a list of numbers in Python 
Python :: print random word python 
Python :: parquet pyspark 
Python :: pandas object to float 
Python :: convert torch to numpy 
Python :: find absolut vale in python 
Python :: how to install python 2 
Python :: how to install python 3.6 ubuntu 
Python :: python wikipedia api search 
Python :: how to pick a random english word from a list 
Python :: access-control-allow-origin django 
Python :: np.loadtext 
Python :: django timezone india 
Python :: change graph colors python matplotlib 
Python :: django filter text first character upper case 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =