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 *args and **kwargs 
Python :: pandas to csv 
Python :: Get the first 4 numbers of the innermost arrays using numpy 
Python :: discordpy make all inputs lowercase 
Python :: df from wikipedia table 
Python :: if start and end point is same in range function python 
Python :: add label to colorbar 
Python :: How do I schedule an email to send at a certain time using cron and smtp, in python 
Python :: python save image pytelegrambotapi 
Python :: python data types 
Python :: hex string to hex number 
Python :: python if index not out of range 
Python :: insta bs2json 
Python :: numpy savetext in one line 
Python :: os.path.dirname(__file__) 
Python :: how to add items to tuple in python 
Python :: for loop in python array 
Python :: pickle.load from gpu device to cpu 
Python :: pandas group by decending 
Python :: python match case example 
Python :: find rules of decision tree python 
Python :: how to find number of categories in python 
Python :: python string name out of mail 
Python :: hide grid imshow 
Python :: message to dict protobuf 
Python :: slice python 
Python :: NumPy fliplr Syntax 
Python :: using polymorphism in python 
Python :: remove hh:mm:ss from pandas dataframe column 
Python :: how to interrupt a loop in python 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =