0

Second: what's the difference nums = [1,2,3,4,5,6] Between? >> nums = nums[-3:] + nums[:-3] || nums[:] = nums[-3:] + nums[:-3]

First question: Difference between -- lst[-1:] and lst[::-1] -- in python [SOLVED] ✓

1st Sep 2021, 3:16 AM
Mahmoud ayman
Mahmoud ayman - avatar
4 Antworten
+ 2
Format is like- list [start : end : step]# step is optional List[::-1] reverses the list For example List=[1,2,3,4,5] print(list[::-1]) #output is [5,4,3,2,1] print(list[-1:]) #output is [5] where index -1 is start point and printing start from 5 print(list[-2:])#output is [4,5] print(list[:-1])#output is [1,2,3,4] where index -1 is end point and printing output till 4,not include 5
1st Sep 2021, 4:03 AM
Myo Thuzar
Myo Thuzar - avatar
+ 1
Thanks, what about nums = [1,2,3,4,5,6] nums = [-3:] + [:-3] nums[:] = [-3:] + [:-3]
1st Sep 2021, 6:13 AM
Mahmoud ayman
Mahmoud ayman - avatar
0
It gonna print syntax error [-3:]+[:-3] is invalid for nums But you can write like that 👇 nums=nums[-3:]+nums[:-3] print(nums) #output is [4,5,6,1,2,3] B.coz you wanna print the value of nums list, so you have to use variable name "nums" and write nums[ -3:] instead of writing like [-3:] for further explanation on list slicing read it there. https://www.learnbyexample.org/JUMP_LINK__&&__python__&&__JUMP_LINK-list-slicing/ https://stackoverflow.com/questions/4081561/what-is-the-difference-between-list-and-list-in-python https://www.geeksforgeeks.org/python-list-slicing/
1st Sep 2021, 6:25 AM
Myo Thuzar
Myo Thuzar - avatar
0
My mistake, I mean what's the difference nums = [1,2,3,4,5,6] Between? nums = nums[-3:] + nums[:-3] nums[:] = nums[-3:] + nums[:-3] Note: i know the output is the same
1st Sep 2021, 6:58 AM
Mahmoud ayman
Mahmoud ayman - avatar