World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITians, only for AI Learners.
Download our e-book of Introduction To Python
4.5 (1,292 Ratings)
a year ago
InsideAIML is Good Plateform for AI & ML. Anyone who wants to make their Carrier in AIML can join here. They started teaches us from Zero.
# opening a text file text_file = open("insideaiml.txt", "r") # setting flag and index to 0 flag = 0 index = 0 keyword = 'join' # Loop through the file line by line for line in text_file: index += 1 # checking string is present in line or not if keyword in line: flag = 1 break # checking condition for string found or not if flag == 0: print('String', text_file, 'Not Found') else: print('String', text_file, 'Found In Line', index) # closing text file text_file.close()
String <_io.TextIOWrapper name='insideaiml.txt' mode='r' encoding='cp1252'> Found In Line 2
keyword = 'AIML' # opening a text file text_file = open("insideaiml.txt", "r") # read file content read_file = text_file.read() # checking condition for string found or not if keyword in read_file: print('String', keyword, 'Found In File') else: print('String', keyword, 'Not Found') # closing a file text_file.close()
String AIML Found In File
# Searching a particular word from a given string str1 = "This is a InsideAIML. How may I help you" str2 = "InsideAIML" print(str1.find(str2)) print(str1.find(str2, 10)) print(str1.find(str2, 40))
10 10 -1