slicing in string

Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec  7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license()" for more information.

>>> ##nested list

>>> list1[1,2,3,4,5,[6,7,8],20,29]

Traceback (most recent call last):

  File "<pyshell#1>", line 1, in <module>

    list1[1,2,3,4,5,[6,7,8],20,29]

NameError: name 'list1' is not defined

>>> list1=[1,2,3,4,5,[10,19,20,30],39,48,49]

>>> list[8]

list[8]

>>> list1[8]

49

>>> list1[5]

[10, 19, 20, 30]

>>> list1[5][3]

30

>>> ##slicing

>>> fruits=["apple","orange","banana","mango","pineapple"]

>>> fruits[::]

['apple', 'orange', 'banana', 'mango', 'pineapple']

>>> fruits[::-1]

['pineapple', 'mango', 'banana', 'orange', 'apple']

>>> fruits[:-4:-1]

['pineapple', 'mango', 'banana']

>>> ##n goes upto n-1(remember)*

>>> 

Comments

Popular posts from this blog

XAMPP, SQL BASIC COMMANDS

The Minion Game Hackerrank Solution

Arrays - DS | HackerRank Solutions