Differences in Python
Differences in Python
The end parameter is used to specify a string that will be printed after the output. However, the sep parameter is
used as a separator between the items that you want to print.
Q. Difference between == and „is‟ operators in Python
We use the is operator when we want to compare two objects‟ identities (memory address). On the other hand,
we use the == operator when we want to compare the two objects‟ values.
Differentiation Table
Basis of Comparison For Loop While Loop
Keyword Uses for keyword Uses while keyword
Used For loop is used when the number of While loop is used when the number of
iterations is already known. iterations is already Unknown.
It is usable inside the whole program and all locks(functions, other It can be used only within this function and
blocks) contained within the program other blocks contained under it
Q. Write the file mode that will be used for opening the following files. Also, write the Python statements to
open the following files:
1. a text file “example.txt” in both read and write mode.
2. a binary file “bfile.dat” in write mode.
3. a text file “try.txt” in append and read mode.
4. a binary file “btry.dat” in read only mode.
Answer
1. File Mode: 'r+'
fh = open("example.txt", "r+")
2. File Mode: 'wb'
fh = open("bfile.dat", "wb")
3. File Mode: 'a+'
fh = open("try.txt", "a+")
4. File Mode: 'rb'
fh = open("btry.dat", "rb")