Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

slice notation python

a[::-1]    # all items in the array, reversed
a[1::-1]   # the first two items, reversed
a[:-3:-1]  # the last two items, reversed
a[-3::-1]  # everything except the last two items, reversed
Comment

slice python

The basic rules of slice are:
I'''
 The slice generates index/integers from - start, start + step, start +
step + step, and so on. All the numbers generated must be less than
the stop value when step is positive.'''
II'''  
 If step value is missing then by default is taken to be 1 '''
III'''
 If start value is missing and step is positive then start value is by default
taken as 0.'''
IV'''
 If stop value is missing and step is positive then start value is by
default taken to mean till you reach the ending index(including the
ending index)'''
V'''
 A negative step value means the numbers are generated in
backwards order i.e. from - start, then start - step, then start -step
-step and so on. All the numbers generated in negative step must
be greater than the stop value.'''
VI'''
 If start value is missing and step is negative then start value takes default
value -1'''
VII'''
 If stop value is missing and step is negative then stop value is by
default taken to be till you reach the first element(including the 0
index element)'''
Comment

slice notation python

a[start:stop:step] # start through not past stop, by step
Comment

slice notation python

a[-1]    # last item in the array
a[-2:]   # last two items in the array
a[:-2]   # everything except the last two items
Comment

PREVIOUS NEXT
Code Example
Python :: python to executable windows 
Python :: vim run python current file 
Python :: selenium webdriver scroll down python 
Python :: python projects with source code 
Python :: python fill zeros left 
Python :: string remove in python 
Python :: python password checker 
Python :: python global variable across files 
Python :: feature to determine image too dark opencv 
Python :: how to unlist a list in python 
Python :: if substring not in string python 
Python :: pandas convert first row to header 
Python :: how to add attribute to class python 
Python :: Matplotlib rotated x tick labels 
Python :: python string format 
Python :: if number is divisible by 3 python 
Python :: Extract bounding boxes OpenCV 
Python :: create new column pandas lambda function assign apply 
Python :: create pyspark dataframe from list 
Python :: how do you change a string to only uppercase in python 
Python :: get_absolute_url django 
Python :: how to print correlation to a feature in pyhton 
Python :: python merge list of lists 
Python :: convert to datetime object 
Python :: how to take multiple line input in python 
Python :: bulk create django 
Python :: python program to find numbers divisible by another number 
Python :: generate random integers in a range python 
Python :: df to sql mysql 
Python :: how to call a random function in python 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =