Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

tuple slicing in 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

Slicing of Tuple in python

# Slicing of a Tuple
 
# Slicing of a Tuple
# with Numbers
Tuple1 = tuple('Softhunt')
 
# Removing First element
print("Removal of First Element: ")
print(Tuple1[1:])
 
# Reversing the Tuple
print("
Tuple after sequence of Element is reversed: ")
print(Tuple1[::-1])
 
# Printing elements of a Range
print("
Printing elements between Range 4-9: ")
print(Tuple1[4:9])
Comment

slicing tuples

# a[start:stop:step], default step is 1
a = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
b = a[1:3] # Note that the last index is not included
print(b)
b = a[2:] # until the end
print(b)
b = a[:3] # from beginning
print(b)
b = a[::2] # start to end with every second item
print(b)
b = a[::-1] # reverse tuple
print(b)
Comment

PREVIOUS NEXT
Code Example
Python :: python face recognition 
Python :: notion python api 
Python :: python program to switch first and second characters in a string 
Python :: python character list to string 
Python :: replace empty numbers in dataframe 
Python :: pandas split dataframe into chunks with a condition 
Python :: pass keyword python 
Python :: python tic tac toe 
Python :: make a gif with images python 
Python :: Python3 boto3 put and put_object to s3 
Python :: pandas copy data from a column to another 
Python :: python find difference between lists 
Python :: python sort array by value 
Python :: Python NumPy split Function Example 
Python :: Roman to integer with python 
Python :: get multiple inputs in python 
Python :: python list for all months including leap years 
Python :: split python strings into pairs & complete uneven pairs 
Python :: tkinter window size 
Python :: python dequeu 
Python :: python recursively merge dictionaries 
Python :: install aws sdk python 
Python :: matplotlib pyplot comment on plot 
Python :: django active link 
Python :: is python good for web development 
Python :: how to convert dataframe to text 
Python :: python text input 
Python :: ocaml add element to end of list 
Python :: Custom x, y-ticks using plt 
Python :: merge multiple excel workssheets into a single dataframe 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =