Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
String slicing
#7
(May-30-2020, 09:30 PM)divyansh Wrote: str1="divyansh tiwari" # this is just a string

var1=str1[-1:-16:1] # in this i know that the slicing will start at -1 index that is the last index and will end on the -16th index that is excluding -16th index but here i used a positive number for steps that is 1 and this kinda slicing is making my control to go beyond the indexes but it is not show a error i am fine with that but its also not showing any output i am fine with that too but lets look down to the var2
print(var1)
var2=str1[-1:16:1] # here same terminology is used but the stopping index in changed to +16 from -16 and this is showing me a output that is prompting me with the last "i" in the string str1
print(var2)

# my question is that why second one is showing a output ( if you say that slicing includes the start index then what happened with the var1 output it is also starting with the same index)

Please, post your code - you should have a first go at it - and also, use proper code tags not pictures, unless code is too big
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply


Messages In This Thread
String slicing - by divyansh - May-30-2020, 09:30 PM
RE: String slicing - by BitPythoner - May-30-2020, 09:44 PM
RE: String slicing - by divyansh - May-30-2020, 10:04 PM
RE: String slicing - by menator01 - May-30-2020, 10:13 PM
RE: String slicing - by bowlofred - May-30-2020, 10:17 PM
RE: String slicing - by ibutun - May-31-2020, 12:55 AM
RE: String slicing - by pyzyx3qwerty - May-31-2020, 06:15 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python3 string slicing Luchano55 4 602 Feb-17-2024, 09:40 AM
Last Post: Pedroski55
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,536 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  String slicing and loop iteration divyansh 9 4,718 Jun-07-2020, 10:29 PM
Last Post: divyansh
  string slicing help oli_action 2 2,183 Mar-22-2020, 09:57 AM
Last Post: oli_action
  Accepting strings as arguments when slicing a string? (Ziyad Yehia on Udemy) Drone4four 4 3,783 Aug-23-2019, 07:59 PM
Last Post: Drone4four
  string slicing default value Uchikago 1 2,812 Jul-01-2019, 11:19 AM
Last Post: perfringo
  string slicing Uchikago 2 2,388 Jun-28-2019, 06:35 AM
Last Post: perfringo
  String slicing in python from reverse ift38375 1 2,394 Apr-29-2019, 06:58 AM
Last Post: perfringo
  String Slicing in List Comphrensions Patroclus72790 1 2,256 Mar-21-2019, 09:33 PM
Last Post: nilamo
  String slicing problem Ollew 4 2,792 Sep-08-2018, 08:07 PM
Last Post: Ollew

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020