Read() Function in Python | Python built-in functions | Python tutorials for beginners

Опубликовано: 05 Май 2020
на канале: ViaDigitally
29
1

#Builtinfunction #ReadFunction #PythonTutorials

Read() Function in Python:
1. This is a built-in function, this function is used to handle the files.
2. This is used to read the data from the given file.
3. In python, the read() is avaiable 4 forms:
a). read()
b). read(n)
c). readline()
d). readlines()
a). read():
This furnction reads the entire data from the given file.
syntax:
read()
ex: to read entire data from a file:


fp = open('sample.txt','r') #to open r mode
d=fp.read() #read total data
print('The sample.txt file content is:')
print(d)

b). read(n):
This function is used to read the 'n' characters only
syntax:
read(n)
here, n is size .

ex: to read first 8 characters from a file:

fp = open('sample.txt','r') #to open r mode
d=fp.read(8) #read 3 characters only
print('The sample.txt file content is:')
print(d)

3. readline():
This function is used to read only one line
syntax:
readline()

ex: to read first line

fp=open('sample.txt','r')
a=fp.readline()
print(a)

ex-2: to read first line

fp=open('sample.txt','r')
a=fp.readline()
b=fp.readline()
c=fp.readline()
print(a)
print(b)
print(c)
fp.close()
d). readlines():
This function is used to read all lines from
a given file.
this funtions returns the result as list type.
ex: to read entire data from a file:
fp=open('sample.txt','r')
d=fp.readlines()
print(d)
for i in d:
print(i)
fp.close()
---------------------------------------------
Python tutorial for beginners| python programming language tutorial
Python basics | python tutorial for beginners | learn python programming from scratch
Python tutorial for beginners - learn python for machine learning and web development.
Python tutorial for beginners | python programming | learn python | great learning.
Python tutorial for beginners [full course] learn python for web development.


Смотрите видео Read() Function in Python | Python built-in functions | Python tutorials for beginners онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь ViaDigitally 05 Май 2020, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 29 раз и оно понравилось 1 людям.