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 :: pandas iloc select certain columns 
Python :: python reverse linked list 
Python :: Getting the Current Working Directory in Python 
Python :: get title attribute beautiful soup 
Python :: django sort descending 
Python :: python get input from console 
Python :: get month name from datetime pandas 
Python :: pandas check if value in column is in a list 
Python :: python convert list to absolute value 
Python :: tkinter open new window 
Python :: python undefine variable 
Python :: how to save a neural network pytorch 
Python :: how to read tuples inside lists python 
Python :: python string replace index 
Python :: pyinstaller command 
Python :: delete all files in a directory python 
Python :: python hello world program 
Python :: decorator python 
Python :: get list file endswith python 
Python :: how to load keras model from json 
Python :: isprime python 
Python :: pd count how many item occurs in another column 
Python :: tkinter frame example 
Python :: n-largest and n-smallest in list in python 
Python :: django urlpattern 
Python :: tdmq python 
Python :: python list to bytes 
Python :: python pywhatkit 
Python :: How to search where a character is in an array in python 
Python :: tf dropout 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =