Answers for "Python Program to Count the Occurrences of a Word in a Text File"

1

Python Program to Count the Occurrences of a Word in a Text File

#get file object reference to the file
file = open("C:\workspace\python\data.txt", "r")
#read content of file to string
data = file.read()
#get number of occurrences of the substring in the string
occurrences = data.count("python")
print('Number of occurrences of the word :', occurrences)
Posted by: Guest on November-11-2020
0

Python Program to Count the Occurrences of a Word in a Text File

object reference to the file
file = open("C:\workspace\python\data.txt", "r")
#read content of file to string
data = file.read()
#get number of occurrences of the substring in the string
occurrences = data.count("python")
print('Number of occurrences of the word :', occurrences)
Posted by: Guest on August-27-2021

Code answers related to "Python Program to Count the Occurrences of a Word in a Text File"

Python Answers by Framework

Browse Popular Code Answers by Language