- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I define duplicate items in a Python tuple?
You can directly enter duplicate items in a Python tuple as it doesn't behave like a set(which takes only unique items).
example
myTpl = (1, 2, 2, 2, 3, 5, 5, 4)
You can also use operators on tuples to compose large tuples.For Example
myTpl = (1,) * 5 print(myTpl)
Output
This will give the output
(1,1,1,1,1)
You can also join tuples using + operator.
example
myTpl = (1,) * 3 + (2,) * 2 print(myTpl)
Output
This will give the output
(1,1,1,2,2)
- Related Articles
- How can I remove items out of a Python tuple?
- How can I append a tuple into another tuple in Python?
- How can I subtract tuple of tuples from a tuple in Python?
- How can I use Multiple-tuple in Python?
- How I can dump a Python tuple in JSON format?
- How can I do Python Tuple Slicing?
- How can I create a non-literal python tuple?
- How I can convert a Python Tuple into Dictionary?
- How can I convert a Python tuple to string?
- How can I represent python tuple in JSON format?
- How can I convert Python strings into tuple?
- How can I create a Python tuple of Unicode strings?
- How can I convert a Python tuple to an Array?
- How do we define tuple in Python?
- How can I convert a Python Named tuple to a dictionary?

Advertisements