Back to Overview

How can I make a tuple out of a list?

Rakib

Rakib

@rakib asked a year ago

Can any please explain how can i create tuple out of a list.

3 Answers

Tanvir Hossain (Tanu)

Tanvir Hossain (Tanu)

@tanvir1017 answered a year ago

In Python, we can use the <yield> keyword to convert any Python function into a Python generator. Yields function similarly to a conventional return keyword. However, it will always return a generator object. A function can also use the <yield> keyword multiple times.

def creating_gen(index):  
  months = ['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec']  
  yield months[index]  
  yield months[index+2]  
next_month = creating_gen(3)  
print(next(next_month), next(next_month))  

Loading...