Ho to find a substring in python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Ho to find a substring in python?

i have been taking python for a while now, and i know how to do that on my logic, but when i applied to the course python for beginners, i found that some logic we used to learn in other websites are not the same with sololearn

19th Aug 2021, 6:22 AM
Jocelin Kisenga
Jocelin Kisenga - avatar
12 Answers
+ 3
The string in print() must be exactly the same as in the task description in order to pass the test cases. Also, some users have reported that playground is not working well these days and sometimes it won't give any output.
19th Aug 2021, 7:36 AM
Lisa
Lisa - avatar
+ 1
Can you share here some examples of those logics with differences from SoloLearn and other sources?
19th Aug 2021, 6:38 AM
Ipang
+ 1
Hmmm okay ... Now give me some samples to test that code with. Better if you can also tell me what the problem is, cause I still don't see the logic diifference from SoloLearn's and other sources.
19th Aug 2021, 7:02 AM
Ipang
0
Like when i use the bult-in function find(). let me just show you my code .
19th Aug 2021, 6:51 AM
Jocelin Kisenga
Jocelin Kisenga - avatar
0
# function to check if small string is # there in big string def search(string, sub_str): if (string.find(sub_str) == -1): print("not found") else: print("found!!") # main code string = input() sub_str = input() search(string, sub_str)
19th Aug 2021, 6:57 AM
Jocelin Kisenga
Jocelin Kisenga - avatar
0
Okay, did you provide the inputs for <string> and <sub_str> in separate line? I had to ask cause many people got stuck on this, thinking input will be interactive. https://code.sololearn.com/WhiNb9BkJUVC/?ref=app
19th Aug 2021, 7:09 AM
Ipang
0
yes sir
19th Aug 2021, 7:12 AM
Jocelin Kisenga
Jocelin Kisenga - avatar
0
I tested your code and it works as expected (given some sample tests). I'm not sure what/why the module test isn't letting you pass ... But just a little note, pay a close attention to the output. I've seen many people got stuck because their output differs to the one given in the task Description, even just by one letter.
19th Aug 2021, 7:21 AM
Ipang
0
Yeah but now i don't know what to do.
19th Aug 2021, 7:28 AM
Jocelin Kisenga
Jocelin Kisenga - avatar
0
I think you're right, cause have tried all my best.
19th Aug 2021, 7:39 AM
Jocelin Kisenga
Jocelin Kisenga - avatar
0
Syntax if {substring} in {mainstring} == True: Returns true if present.
20th Aug 2021, 7:15 AM
King Infinity
King Infinity - avatar
- 1
the problem is that when i apply this simple code on my python module test, it's not giving results. but on my Ide everything is perfect.
19th Aug 2021, 7:04 AM
Jocelin Kisenga
Jocelin Kisenga - avatar