This tutorial will show how to give a Python list an initial value.
To initialize list myTuple values to 0, with 10 items:
1 | myTuple = [0]*10 |
If we need to have 5 items of a tuple with the value 0 and the rest 5 with the value 1:
1 | myTuple = [0]*5 + [1]*5 |
To initialize list myList values to 0, with 10 items:
1 | myList = (0,)*10 |
If we need to have 5 item of list with the value 0 and the rest 5 with the value 1:
1 | myList = (0,)*5 + (1,)*5 |
For list, don’t forget the comma ‘,’. It means one item.
Related Articles:
Popular Articles:
- Backup folders with 7-zip command line
- Insert figures to LaTeX
- Create LaTeX table easily
- Add personal signature to Lotus Notes 7
- Windows XP Service Pack 3 Final release download
Spread/Promote this article.
Digg | Del.icio.us | Stumble | Y! MyWeb | Y! Buzz | Fave It! | RedditSubscribe for free.
Subscribe to Selinap.com feed right now!
Tags: initialize, list, Python, tuple
