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â€)
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
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
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
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’
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
Correct syntax of file.readlines() is?
1.fileObject.readlines( sizehint );
2.fileObject.readlines();
3.fileObject.readlines(sequence)
4.none of the mentioned
Correct syntax of file.writelines() is?
1.file.writelines(sequence)
2.fileObject.writelines()
3. fileObject.writelines(sequence)
4.none of the mentioned
In file handling, what does this terms means “r, a�
1.read, append
2.append, read
3. write, append
4.none of the mentioned
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
The readlines() method returns _______
1. str
2.a list of lines
3.a list of single characters
4. a list of integers
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â€)
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â€)
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()
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()
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()
To read two characters from a file object infile, we use _______
1.infile.read(2)
2.infile.read()
3.infile.readline()
4.infile.readlines()
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
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
What is the use of “a†in file handling?
1.Read
2.Write
3.Append
4.none of the mentioned
What is the use of “w†in file handling?
1. Read
2.Write
3.Append
4.none of the mentioned
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
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
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
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’]
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
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
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
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
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’]
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’
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’
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’
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’]
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
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
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
Which function is used to read all the characters?
1.Read()
2.Readcharacters()
3.Readall()
4.Readchar()
Which function is used to read single line from file?
1. Readline()
2.Readlines()
3.Readstatement()
4.Readfullline()
Which function is used to write a list of string in a file?
1. writeline()
2.writelines()
3.writestatement()
4. writefullline()
Which function is used to write all the characters?
1.write()
2.writecharacters()
3.writeall()
4.writechar()
Which is/are the basic I/O connections in file?
1.Standard Input
2.Standard Output
3.Standard Errors
4.all of the mentioned
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’)
Which of the following functions does not accept any argument?
1.re.purge
2.re.compile
3. re.findall
4.re.match
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
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’)
Which of the following mode will refer to binary data?
1. r
2.w
3.+
4.b
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
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’
Which one of the following is not attributes of file?
1.closed
2. softspace
3.rename
4.Model