Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to modify tuples python

#modify tuples using slicing
my_tuple = (1,2,3,4,5,6,7)
sliced_tuple = my_tuple[1:4] # indexes 0 to 3
Comment

Python Changing a Tuple

# Changing tuple values
my_tuple = (4, 2, 3, [6, 5])


# TypeError: 'tuple' object does not support item assignment
# my_tuple[1] = 9

# However, item of mutable element can be changed
my_tuple[3][0] = 9    # Output: (4, 2, 3, [9, 5])
print(my_tuple)

# Tuples can be reassigned
my_tuple = ('p', 'r', 'o', 'g', 'r', 'a', 'm', 'i', 'z')

# Output: ('p', 'r', 'o', 'g', 'r', 'a', 'm', 'i', 'z')
print(my_tuple)
Comment

change tuple python

# Change Value In Tuple :-

friends = ("Mido", "Lucifer", "Abdelrhman")

# Example => Wanna Change ( Abdelrhman ) To ( Aiiob );
# First We Need Transformation From Tuple To List ,
# We Need To Create Variable With Any Name 
# After This We Use list() Function

oneName = list(friends)

# After This We Need Change The Value ,

oneName[-1] = "Aiiob"

# After This We Need Transformation From List To Tuple ,
# We Use tuple() Function

friends = tuple(oneName)

# And We Done (:
Comment

PREVIOUS NEXT
Code Example
Python :: python split string with a seperator 
Python :: python area calculator 
Python :: how to combine two lists in python 
Python :: open a python script on click flask 
Python :: web socket in python 
Python :: remove trailing zeros python 
Python :: intersection of three arrays 
Python :: return dataframe as csv flask 
Python :: SUMOFPROD1 
Python :: change list item in python 
Python :: reading from a file in python 
Python :: axvline matplotlib 
Python :: learn basic facts about dataframe | dataframe info 
Python :: to_frame pandas 
Python :: i have two versions of python installed mac 
Python :: django check if get parameter exists 
Python :: get data from model with field name in django 
Python :: Max fonction code in python 
Python :: merge two sorted arrays python 
Python :: python form html 
Python :: remove extra blank spaces 
Python :: how to sort dictionary in ascending order by sorted lambda function in python 
Python :: pandas check if column is object type 
Python :: get length of string python 
Python :: how to add one to a variable in python 
Python :: django redirect url 
Python :: what is serialization in django 
Python :: generate hmach sha256 hash in python 
Python :: append to list in dict python 
Python :: API curl python pandas 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =