- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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 create a non-literal python tuple?
You can first construct a list then change the single value you want to change, then finally convert that to a tuple if you want to create a non-literal python tuple. For example,
def create_non_literal_tuple(a, b, c): x = [1] * a x[c] = b return tuple(x) create_non_literal_tuple(6, 0, 2)
This will give the output:
(1, 1, 0, 1, 1, 1)
A 0 in position 2 of an array of length 6.
Advertisements