Python Forum
Accepting strings as arguments when slicing a string? (Ziyad Yehia on Udemy)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Accepting strings as arguments when slicing a string? (Ziyad Yehia on Udemy)
#5
@ThomasL: You did a splendid job clarifying the syntax and semantics as you explain the index method.

@perfringo: I appreciate your sense of humour regarding the ValueError pun. Your use of type() and help() is instructive.

@newbieAuggie2019: That is certainly a creative way of replicating the same operation using the split() method instead of the index() method.

I set up a second string which is similar to the first but which this time is separated by a period “.” See here:

>>> string_two = "happy.birthday"
>>> string_two[string_two.index("."):]
'.birthday'
I shifted the casting method to the opposite side of the colon so that it grabs ‘birthday’ (instead of ‘happy’). However as you can see, the period is included. To omit the period, I just added “+1”. See here:

>>> string_two[string_two.index(".")+1:]
'birthday'
>>> 
Hooray!

I feel like I have come to know slicing much better now. I appreciate the help from all of you. Thanks.
Reply


Messages In This Thread
RE: Accepting strings as arguments when slicing a string? (Ziyad Yehia on Udemy) - by Drone4four - Aug-23-2019, 07:59 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python3 string slicing Luchano55 4 602 Feb-17-2024, 09:40 AM
Last Post: Pedroski55
  Trying to understand strings and lists of strings Konstantin23 2 758 Aug-06-2023, 11:42 AM
Last Post: deanhystad
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,537 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  Passing string functions as arguments Clunk_Head 3 1,246 Jun-15-2022, 06:00 AM
Last Post: Gribouillis
  Splitting strings in list of strings jesse68 3 1,758 Mar-02-2022, 05:15 PM
Last Post: DeaD_EyE
  Search multiple CSV files for a string or strings cubangt 7 8,006 Feb-23-2022, 12:53 AM
Last Post: Pedroski55
  TypeError: not enough arguments for format string MaartenRo 6 2,920 Jan-09-2022, 06:46 PM
Last Post: ibreeden
  String slicing and loop iteration divyansh 9 4,720 Jun-07-2020, 10:29 PM
Last Post: divyansh
  String slicing divyansh 6 3,353 May-31-2020, 06:15 AM
Last Post: pyzyx3qwerty
  question: finding multiple strings within string djf123 4 2,959 May-16-2020, 01:00 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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