click below
click below
Normal Size Small Size show me how
IT0011 FA3
| Question | Answer |
|---|---|
| Given the code below: a = “Learning, Python!” print (a[2:4]) What will be the output? | Ar |
| Given the code below: a = “Learning” b = “Python” c = a + b print (c) What will be the output? | LearningPython |
| Given the code below: b = “Learning” print (len(b)) What will be the output? | 8 |
| Python does not have a character data type, a single character is simply a string with a length of 1. | T |
| To get the length of a string, use the strip() function. | F |
| An example of an illegal character is a double quote inside a string that is surrounded by double quotes. | T |
| Given the code below: a = ‘the quick brown fox’ print (a[-3:]) What will be the output? | fox |
| The split() method splits the string into substrings if it finds instances of the separator. | T |
| Given the code below: b = “Python” print (len(b)) What will be the output? | 6 |
| Given the code below: x = “Success” print (len(x)) What will be the output? | 7 |
| What does the <readlines> method returns? | list of lines |
| In the open() method, the first parameter is the name of a file including its path. | T |
| Which of the following is used to open a file for both appending and reading? | a+ |
| A file method used to save the contents of a list of object in a file. | writelines() |
| Which of the following is used to open a file for appending in binary format? | ab+ |
| To open a file in binary format, add "a" to the mode parameter. | F |
| The buffer size argument is an optional parameter which decides the purpose of opening a file, e.g. read, write, append, etc. | F |
| The built-in function bytearray() returns a byte representation of the object. | T |
| The access mode parameter is an optional parameter which decides the purpose of opening a file, e.g. read, write, append, etc. | T |
| readline() method reads the characters starting from the current reading position up to a newline character. | T |
| Given the code below: a = ‘the quick brown fox’ print (a[:10]) What will be the output? | the quick |
| Given the code below: a = ‘the quick brown fox’ print (a.upper ()) What will be the output? | THE QUICK BROWN FOX |
| Given the code below: a = “Study, Program” print (a[-4:]) What will be the output? | gram |
| Square brackets can be used to access elements of the string. | T |
| String literals in python are surrounded by brackets. | F |
| The lower() method removes any whitespace from the beginning or the end. | F |
| The strip() method splits the string into substrings if it finds instances of the separator. | F |
| Given the code below: a = “Learning, Python!” print (a[-5:-2]) What will be the output? | tho |
| To open a file in binary format, add "___" to the mode parameter. | b |
| Which of the following is used to open a file for appending? | a |
| “____" mode allows reading only and not writing. | r |
| Which of the following command is used to open a file “c:\tempt.txt” in reading mode only? | file = open(“c:\\temp.txt”, “r”) |
| Which of the following is used to open a file for both reading and writing in binary format? | rb+ |
| The writelines() method used to save the contents of a list object in a file. | T |
| Which of the following is incorrect file handling mode in Python. | xr |
| Which of the following is incorrect file handling mode in Python. | t+ |
| You develop a Python application for your school. You need to read and write data to a text file. If the file does not exist it must be created. If the file has content the content must be removed. | open(“local_data”, “w+”) |
| The replace() method replaces a string with another string. | T |
| Given the code below: b = “Learning, Python!” print (len(b)) What will be the output? | 17 |
| The strip() method returns the string in lower case. | F |
| The len() method takes the passed arguments. | T |
| Given the code below: a = “Learning” b = “Python” c = a + b print (c) What will be the output? | LearningPython |
| An example of an illegal character is a double quote inside a string that is surrounded by double quotes. | T |
| The lower() method returns the string in lower case. | T |
| Given the code below: a = “Learning” b = “Python” c = a + “ “ + b print (c) What will be the output? | Learning Python |
| Which of the following is used to open a file for writing only? | w |
| The file object has an inbuilt iterator. | T |
| read(chars) method reads the specified number of characters starting from the current position. | T |
| You need to read a file object that will be mapped to an image file called abc.txt. Which of the following is the correct syntax to use. | open('abc.txt','r') |
| Which of the following is incorrect file handling mode in Python. | v |
| The readline() method used to save the contents of a list object in a file. | F |
| Which of the following is used to open a file for writing only in binary format? | wb+ |
| In order to add more data to existing file use the "a" or "a-" mode. | T |
| Which of the following is incorrect file handling mode in Python. | rz |
| Which of the following is incorrect file handling mode in Python. | t+ |