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 :: max of a list in python 
Python :: add dataframe column to set 
Python :: data type 
Python :: pandas python tutorial 
Python :: numpy arange number of elements 
Python :: combination in python math 
Python :: python print array line by line 
Python :: tri python 
Python :: beautifulsoup docs 
Python :: how to create models in django 
Python :: what is a thread in os 
Python :: python developer job description 
Python :: how to learn regex pyton 
Python :: python add 1 
Python :: change version of python that poetry use 
Python :: indent python 
Python :: decoding 
Python :: how to make a programming language in python 
Python :: python for print 
Python :: example exponential distribution python 
Python :: pyaudio mic stream 
Python :: negate an int in python 
Python :: string to list of characters python 
Python :: bitcoin with python 
Python :: list append string 
Python :: reciprocal python 
Python :: traduce query model 
Python :: sklearn pipeline with interactions python 
Python :: projects for beginners in python to complete 
Shell :: error: cannot install "code": classic confinement requires snaps under /snap or symlink from /snap 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =