Python/Python Mcq Set 18 Sample Test,Sample questions

adplus-dvertising

Question:
 To open a file c:scores.txt for writing, we use ____

1. outfile = open(“c:scores.txt”, “w”)

2.outfile = open(“c:\scores.txt”, “w”)

3. outfile = open(file = “c:scores.txt”, “w”)

4.outfile = open(file = “c:\scores.txt”, “w”)

Posted Date:-2022-01-02 03:50:28


Question:
 What is the correct syntax of open() function?

1. file = open(file_name [, access_mode][, buffering])

2.file object = open(file_name [, access_mode][, buffering])

3.file object = open(file_name)

4.none of the mentioned

Posted Date:-2022-01-02 04:13:47


Question:
 What is the pickling?

1.It is used for object serialization

2.It is used for object deserialization

3.None of the mentioned

4.all of the mentioned

Posted Date:-2022-01-02 04:12:57


Question:
 What is unpickling?

1.It is used for object serialization

2.It is used for object deserialization

3.None of the mentioned

4.all of the mentioned

Posted Date:-2022-01-02 04:13:20


Question:
 What will be the output of the following Python code?

import re
s = 'abc123 xyz666 lmn-11 def77'
re.sub(r'([a-z]+)(d+)', r'21:', s)

1.‘123abc: 666xyz: lmn-11 77def:’

2.‘77def: lmn-11: 666xyz: 123abc’

3. ‘abc123:’, ‘xyz666:’, ‘lmn-11:’, ‘def77:’

4.‘abc123: xyz666: lmn-11: def77’

Posted Date:-2022-01-02 03:42:16


Question:
 What will be the output of the following Python code?

str = input("Enter your input: ");
print "Received input is : ", str

1.Enter your input: [x*5 for x in range(2,10,2)] Received input is : [x*5 for x in range(2,10,2)]

2.Enter your input: [x*5 for x in range(2,10,2)] Received input is : [10, 30, 20, 40]

3.Enter your input: [x*5 for x in range(2,10,2)] Received input is : [10, 10, 30, 40]

4. None of the mentioned

Posted Date:-2022-01-02 04:07:32


Question:
Correct syntax of file.readlines() is?

1.fileObject.readlines( sizehint );

2.fileObject.readlines();

3.fileObject.readlines(sequence)

4.none of the mentioned

Posted Date:-2022-01-02 04:15:10


Question:
Correct syntax of file.writelines() is?

1.file.writelines(sequence)

2.fileObject.writelines()

3. fileObject.writelines(sequence)

4.none of the mentioned

Posted Date:-2022-01-02 04:14:45


Question:
In file handling, what does this terms means “r, a”?

1.read, append

2.append, read

3. write, append

4.none of the mentioned

Posted Date:-2022-01-02 04:15:53


Question:
In the functions re.search.start(group) and re.search.end(group), if the argument groups not specified, it defaults to _____

1. Zero

2.None

3.One

4.error

Posted Date:-2022-01-02 03:43:43


Question:
The readlines() method returns _______

1. str

2.a list of lines

3.a list of single characters

4. a list of integers

Posted Date:-2022-01-02 03:54:01


Question:
To open a file c:scores.txt for appending data, we use _______

1. outfile = open(“c:\scores.txt”, “a”)

2.outfile = open(“c:\scores.txt”, “rw”)

3. outfile = open(file = “c:scores.txt”, “w”)

4.outfile = open(file = “c:\scores.txt”, “w”)

Posted Date:-2022-01-02 03:50:52


Question:
To open a file c:scores.txt for reading, we use ______

1.infile = open(“c:scores.txt”, “r”)

2. infile = open(“c:\scores.txt”, “r”)

3.infile = open(file = “c:scores.txt”, “r”)

4.infile = open(file = “c:\scores.txt”, “r”)

Posted Date:-2022-01-02 03:50:03


Question:
To read the entire remaining contents of the file as a string from a file object infile, we use ____

1. infile.read(2)

2. infile.read()

3. infile.readline()

4.infile.readlines()

Posted Date:-2022-01-02 03:52:17


Question:
To read the next line of the file from a file object infile, we use ______

1. infile.read(2)

2. infile.read()

3.infile.readline()

4. infile.readlines()

Posted Date:-2022-01-02 03:53:09


Question:
To read the remaining lines of the file from a file object infile, we use _______

1. infile.read(2)

2.infile.read()

3. infile.readline()

4. infile.readlines()

Posted Date:-2022-01-02 03:53:38


Question:
To read two characters from a file object infile, we use _______

1.infile.read(2)

2.infile.read()

3.infile.readline()

4.infile.readlines()

Posted Date:-2022-01-02 03:51:49


Question:
What is the current syntax of remove() a file?

1.remove(file_name)

2.remove(new_file_name, current_file_name,)

3.remove(() , file_name))

4.none of the mentioned

Posted Date:-2022-01-02 04:09:23


Question:
What is the current syntax of rename() a file?

1. rename(current_file_name, new_file_name)

2.rename(new_file_name, current_file_name,)

3.rename(()(current_file_name, new_file_name))

4. None of the mentioned

Posted Date:-2022-01-02 04:08:55


Question:
What is the use of “a” in file handling?

1.Read

2.Write

3.Append

4.none of the mentioned

Posted Date:-2022-01-02 04:16:44


Question:
What is the use of “w” in file handling?

1. Read

2.Write

3.Append

4.none of the mentioned

Posted Date:-2022-01-02 04:16:22


Question:
What is the use of seek() method in files?

1.sets the file’s current position at the offset

2.sets the file’s previous position at the offset

3.sets the file’s current position within the file

4.none of the mentioned

Posted Date:-2022-01-02 04:09:48


Question:
What is the use of tell() method in python?

1.tells you the current position within the file

2. tells you the end position within the file

3.tells you the file is opened or not

4.none of the mentioned

Posted Date:-2022-01-02 04:08:30


Question:
What is the use of truncate() method in file?

1. truncates the file size

2.deletes the content of the file

3.deletes the file size

4.none of the mentioned

Posted Date:-2022-01-02 04:10:13


Question:
What will be the output of the following Python code?

a = re.compile('0-9')
a.findall('3 trees')

1. []

2.[‘3’]

3.Error

4.[‘trees’]

Posted Date:-2022-01-02 03:47:59


Question:
What will be the output of the following Python code?

a=re.compile('[0-9]+')
a.findall('7 apples and 3 mangoes')

1.[‘apples’ ‘and’ ‘mangoes’]

2.(7, 4)

3.[‘7’, ‘4’]

4.error

Posted Date:-2022-01-02 03:44:37


Question:
What will be the output of the following Python code?

f = None
for i in range (5):
    with open("data.txt", "w") as f:
        if i > 2:
            break
print(f.closed)

1.True

2.False

3.None

4.error

Posted Date:-2022-01-02 03:52:42


Question:
What will be the output of the following Python code?

fo = open("foo.txt", "wb")
print "Name of the file: ", fo.name
fo.flush()
fo.close()

1.Compilation Error

2.Runtime Error

3.No Output

4.Flushes the file when closing them

Posted Date:-2022-01-02 04:14:17


Question:
What will be the output of the following Python code?

m = re.search('a', 'The blue umbrella')
m.re.pattern

1.{}

2.‘The blue umbrella’

3. ‘a’

4.No output

Posted Date:-2022-01-02 03:48:55


Question:
What will be the output of the following Python code?

re.split(r'(a)(t)', 'Maths is a difficult subject')

1. [‘M a t h s i s a d i f f i c u l t s u b j e c t’]

2.[‘Maths’, ‘is’, ‘a’, ‘difficult’, ‘subject’]

3.‘Maths is a difficult subject’

4.[‘M’, ‘a’, ‘t’, ‘hs is a difficult subject’]

Posted Date:-2022-01-02 03:41:28


Question:
What will be the output of the following Python code?

re.split(r's+', 'Chrome is better than explorer', maxspilt=3)

1.[‘Chrome’, ‘is’, ‘better’, ‘than’, ‘explorer’]

2.[‘Chrome’, ‘is’, ‘better’, ‘than explorer’]

3.(‘Chrome’, ‘is’, ‘better’, ‘than explorer’)

4. ‘Chrome is better’ ‘than explorer’

Posted Date:-2022-01-02 03:44:13


Question:
What will be the output of the following Python code?

re.sub('Y', 'X', 'AAAAAA', count=2)

1.'YXAAAA’

2. (‘YXAAAA’)

3. (‘AAAAAA’)

4.‘AAAAAA’

Posted Date:-2022-01-02 03:49:23


Question:
What will be the output of the following Python code?

re.subn('A', 'X', 'AAAAAA', count=4)

1. ‘XXXXAA, 4’

2.‘AAAAAA’, 4)

3. (‘XXXXAA’, 4)

4. ‘AAAAAA, 4’

Posted Date:-2022-01-02 03:42:54


Question:
What will be the output of the following Python code?

w = re.compile('[A-Za-z]+')
w.findall('It will rain today')

1. ‘It will rain today’

2.(‘It will rain today’)

3. [‘It will rain today’]

4.[‘It’, ‘will’, ‘rain’, ‘today’]

Posted Date:-2022-01-02 03:43:18


Question:
What will be the output of the following Python code?
import sys
sys.stdout.write(' Hello
')
sys.stdout.write('Python
')

1.Compilation Error

2.Runtime Error

3. Hello Python

4.Hello Python

Posted Date:-2022-01-02 04:11:58


Question:
What will be the output of the following Python code? (If entered name is sanfoundry)

import sys
print 'Enter your name: ',
name = ''
while True:
   c = sys.stdin.read(1)
   if c == '
':
      break
   name = name + c
 
print 'Your name is:', name

1.sanfoundry

2.sanfoundry, sanfoundry

3.San

4.none of the mentioned

Posted Date:-2022-01-02 04:11:19


Question:
Which are the two built-in functions to read a line of text from standard input, which by default comes from the keyboard?

1.Raw_input & Input

2. Input & Scan

3.Scan & Scanner

4.Scanner

Posted Date:-2022-01-02 04:06:47


Question:
Which function is used to read all the characters?

1.Read()

2.Readcharacters()

3.Readall()

4.Readchar()

Posted Date:-2022-01-02 04:17:13


Question:
Which function is used to read single line from file?

1. Readline()

2.Readlines()

3.Readstatement()

4.Readfullline()

Posted Date:-2022-01-02 04:17:47


Question:
Which function is used to write a list of string in a file?

1. writeline()

2.writelines()

3.writestatement()

4. writefullline()

Posted Date:-2022-01-02 04:18:44


Question:
Which function is used to write all the characters?

1.write()

2.writecharacters()

3.writeall()

4.writechar()

Posted Date:-2022-01-02 04:18:13


Question:
Which is/are the basic I/O connections in file?

1.Standard Input

2.Standard Output

3.Standard Errors

4.all of the mentioned

Posted Date:-2022-01-02 04:10:49


Question:
Which of the codes shown below results in a match?

1.re.match(‘George(?=Washington)’, ‘George Washington’)

2. re.match(‘George(?=Washington)’, ‘George’)

3.re.match(‘George(?=Washington)’, ‘GeorgeWashington’)

4. re.match(‘George(?=Washington)’, ‘Georgewashington’)

Posted Date:-2022-01-02 03:40:43


Question:
Which of the following functions does not accept any argument?

1.re.purge

2.re.compile

3. re.findall

4.re.match

Posted Date:-2022-01-02 03:47:24


Question:
Which of the following functions returns a dictionary mapping group names to group numbers?

1. re.compile.group

2.re.compile.groupindex

3. re.compile.index

4. re.compile.indexgroup

Posted Date:-2022-01-02 03:45:45


Question:
Which of the following lines of code will not show a match?

1. >>> re.match(‘ab*’, ‘a’)

2.>>> re.match(‘ab*’, ‘ab’)

3. >>> re.match(‘ab*’, ‘abb’)

4.>>> re.match(‘ab*’, ‘ba’)

Posted Date:-2022-01-02 03:48:26


Question:
Which of the following mode will refer to binary data?

1. r

2.w

3.+

4.b

Posted Date:-2022-01-02 04:12:23


Question:
Which of the following statements are true?

1.When you open a file for reading, if the file does not exist, an error occurs

2.When you open a file for writing, if the file does not exist, a new file is created

3.When you open a file for writing, if the file exists, the existing file is overwritten with the new file

4.all of the mentioned

Posted Date:-2022-01-02 03:51:21


Question:
Which of the following statements regarding the output of the function re.match is incorrect?

1. ‘pq*’ will match ‘pq’

2. ‘pq?’ matches ‘p’

3.‘p{4}, q’ does not match ‘pppq’

4. ‘pq+’ matches ‘p’

Posted Date:-2022-01-02 03:46:42


Question:
Which one of the following is not attributes of file?

1.closed

2. softspace

3.rename

4.Model

Posted Date:-2022-01-02 04:08:01


More MCQS

  1. Python MCQS - Function
  2. Python MCQS - GUI in python
  3. Python MCQS - Operators
  4. Python MCQS - Data type in python
  5. Python MCQS - loops in python
  6. Python MCQS - Numpy
  7. Python MCQS - sqlite3
  8. Python MCQS - Library
  9. Python MCQS - Pandas
  10. Python MCQs
  11. Dictionary Python MCQ set 1
  12. Dictionary Python MCQ set 2
  13. MCQ For Python Fundamentals
  14. MCQ Introduction to Python Section 1
  15. MCQ Introduction to Python Section 2
  16. MCQ Introduction to Python Section 3
  17. MCQ on Flow of Control in Python Set 1
  18. MCQ on Flow of Control in Python Set 2
  19. MCQ on Python String Set 1
  20. File Handling in Python section 1
  21. File Handling in Python section 2
  22. Python Functions MCQS Set 1
  23. Python Functions MCQS Set 2
  24. MCQ on List in Python
  25. Pandas MCQ Questions Set 1
  26. Pandas MCQ Questions Set 2
  27. Tuple MCQ in Python
  28. Python dataframe MCQ
  29. Python Mcq Set 1
  30. Python Mcq Set 2
  31. Python Mcq Set 3
  32. Python Mcq Set 4
  33. Python Mcq Set 5
  34. Python Mcq Set 6
  35. Python Mcq Set 7
  36. Python Mcq Set 8
  37. Python Mcq Set 9
  38. Python Mcq Set 10
  39. Python Mcq Set 11
  40. Python Mcq Set 12
  41. Python Mcq Set 13
  42. Python Mcq Set 14
  43. Python Mcq Set 15
  44. Python Mcq Set 16
  45. Python Mcq Set 17
  46. Python Mcq Set 18
  47. Python Mcq Set 19
  48. Python Mcq Set 20
  49. Python Mcq Set 21
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!