I have a sub-string: Show
I have another string:
How do I find if
the Tin Man 156k41 gold badges209 silver badges297 bronze badges asked Sep 9, 2011 at 11:55
0 with
answered Sep 9, 2011 at 11:57
MarcoSMarcoS 13.2k6 gold badges40 silver badges62 bronze badges 5
(By the way - try to not name a variable answered Sep 9, 2011 at 11:57
AmberAmber 488k81 gold badges617 silver badges545 bronze badges 1 If you're looking for more than a True/False, you'd be best suited to use the re module, like:
the Tin Man 156k41 gold badges209 silver badges297 bronze badges answered Nov 23, 2011 at 14:09
ewegesinewegesin 2293 silver badges3 bronze badges 2 People mentioned First of all there is not a Second the answered Jan 19, 2015 at 20:40
Samuel LiSamuel Li 3275 silver badges6 bronze badges Thought I would add this in case you are looking at how to do this for a technical
interview where they don't want you to use Python's built-in function
the Tin Man 156k41 gold badges209 silver badges297 bronze badges answered Mar 27, 2015 at 19:08
1 You can also try
Guy Avraham 3,2743 gold badges37 silver badges46 bronze badges answered Sep 27, 2014 at 14:29
answered Sep 9, 2011 at 11:57
Fredrik PihlFredrik Pihl 43.5k7 gold badges81 silver badges130 bronze badges
answered Jun 23, 2015 at 3:30
1 Can also use this method
answered Nov 21, 2016 at 15:38
jackotonyejackotonye 3,37619 silver badges28 bronze badges Instead Of using find(), One of the easy way is the Use of 'in' as above. if 'substring' is present in 'str' then if part will execute otherwise else part will execute. answered May 7, 2018 at 11:42
Dcoder14Dcoder14 1,6713 gold badges11 silver badges22 bronze badges Which method would you use to determine whether a substring is present in a string?Using index()
The string. index() method returns the starting index of the substring passed as a parameter. However, a major con is that it returns a ValueError in case the substring does not exist. We can solve this by using a Try Except.
Which method would you use to determine whether a certain substring is present in a string quizlet?Which method would you use to determine whether a certain substring is present in a string? The strip() method returns a copy of the string with all the leading whitespace characters removed but does not remove trailing whitespace characters.
Which method would you use to determine whether a certain substring is a suffix?Which method would you use to determine whether a certain substring is the suffix of a string? In slicing, if the end index specifies a position beyond the end of the string, Python will use the length of the string instead.
Which of the following string methods can be used to determine if a string contains only \n?Which of the following string methods can be used to determine if a string contains only '\n' characters? The right side of the '*' must be an integer.
|