
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
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.
- Related Articles
- Python Program to create a Tuple using tuple literal
- How can I create a Python tuple of Unicode strings?
- 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 do Python Tuple Slicing?
- How I can convert a Python Tuple into Dictionary?
- How can I convert a Python tuple to string?
- How can I use Multiple-tuple in Python?
- How can I convert Python strings into tuple?
- How can I remove items out of a Python tuple?
- How can I define duplicate items in a Python tuple?
- How can I convert a Python tuple to an Array?
- How I can dump a Python tuple in JSON format?
- How can I convert a Python Named tuple to a dictionary?
- How we can create a dictionary from a given tuple in Python?

Advertisements