DSSSB TGT / PGT · Computer Science

Python Previous Year Questions

29 Python (Computer Science) questions asked in DSSSB TGT / PGT previous year papers, each with the correct answer and explanation. Read them free on UTpaper, or attempt the full papers as timed online tests.

  • 29 questions
  • Official answer key
  • Free

Other Computer Science topics

Q1From DSSSB TGT Computer Science Practice Set 5
Which method out of the following will allow the read operation from a Binary file in a Python program?
  1. Aread
  2. Binput
  3. Caccept
  4. Dload
Show answerHide answer

Correct answer: (A) read

Explanation

read() reads bytes from a file opened in binary mode ('rb'). input() reads from the keyboard.

Q2From DSSSB TGT Computer Science Practice Set 4
Consider the following dictionary: Num = {10 : 'Ten', 100 : 'Hundred', 10: 'Decimal'} What shall be the output of print (Num)?
  1. A{10 : 'Ten', 100 : 'Hundred', 10 : 'Decimal'}
  2. B{10 : 'Ten', 100 : 'Hundred'}
  3. C{10 : 'Decimal', 100 : 'Hundred'}
  4. DError
Show answerHide answer

Correct answer: (C) {10 : 'Decimal', 100 : 'Hundred'}

Explanation

Dictionary keys must be unique. The second 10 overwrites the first value but keeps the key's original position, giving {10: 'Decimal', 100: 'Hundred'}.

Q3From DSSSB TGT Computer Science Practice Set 4
Which out of the following mode is required to be used while opening a binary file to allow read as well as write operations in a Python program?
  1. Aab
  2. Bwb
  3. Cr+
  4. Drb+
Show answerHide answer

Correct answer: (D) rb+

Explanation

'rb+' opens an existing binary file for both reading and writing. 'r+' is the text-mode version, and 'wb'/'ab' only write or append.

Q4From DSSSB TGT Computer Science Practice Set 3
For the following Python statement Txt=list ('PEACE') What shall be the output of print (Txt)?
  1. A['P', 'E', 'A', 'C', 'E']
  2. B[P, E, A, C, E]
  3. CError in statement
  4. D['PEACE']
Show answerHide answer

Correct answer: (A) ['P', 'E', 'A', 'C', 'E']

Explanation

list() on a string makes a list of its individual characters, so list('PEACE') gives ['P', 'E', 'A', 'C', 'E'].

Q5From DSSSB TGT Computer Science Practice Set 3
Which out of the following is considered as a membership operator in Python?
  1. AIn
  2. BOr
  3. CNot
  4. DIs
Show answerHide answer

Correct answer: (A) In

Explanation

Python's membership operators are 'in' and 'not in'. 'is' is an identity operator, and 'or'/'not' are logical operators.

Q6From DSSSB TGT Computer Science Practice Set 3
Which string method, out of the following will always break the string into 3 parts in Python?
  1. ABreak
  2. BPartition
  3. CMid
  4. DSplit
Show answerHide answer

Correct answer: (B) Partition

Explanation

str.partition(sep) always returns a 3-tuple: the part before the separator, the separator, and the part after it. split() can return any number of parts.

Q7From DSSSB TGT Computer Science Practice Set 2
Identify the Logical Operator used in Python out of the following.
  1. Aand
  2. Bin
  3. C<=
  4. D+=
Show answerHide answer

Correct answer: (A) and

Explanation

and is a logical operator in Python (as are or and not). in is a membership operator, <= is relational and += is assignment.

Q8From DSSSB TGT Computer Science Practice Set 2
Which of the following cannot be used as a valid identifier in Python?
  1. A1st Name
  2. BName1
  3. CName_1
  4. DFirstName
Show answerHide answer

Correct answer: (A) 1st Name

Explanation

Python identifiers cannot start with a digit or contain spaces, so "1st Name" is invalid.

Q9From DSSSB TGT Computer Science Practice Set 2
Which of the following Function Headers in a Python code will result in error?
  1. Adef Compu (X = 100, Y = 10, Z):
  2. Bdef Compu (X, Y, Z = 1):
  3. Cdef Compu (X=100, Y =10, Z=1):
  4. Ddef Compu (X, Y = 10, Z = 1):
Show answerHide answer

Correct answer: (A) def Compu (X = 100, Y = 10, Z):

Explanation

A parameter without a default value cannot follow parameters that have default values. def Compu(X=100, Y=10, Z): raises a SyntaxError.

Q10From DSSSB TGT Computer Science Practice Set 1
What minimum and maximum values will be generated for the following Python statement? print (random.randrange (100)+1)
  1. A1 and 100
  2. B0 and 100
  3. C1 and 99
  4. D0 and 99
Show answerHide answer

Correct answer: (A) 1 and 100

Explanation

random.randrange(100) returns an integer from 0 to 99 (the stop value is excluded). Adding 1 gives a range of 1 to 100.

Q11From DSSSB TGT Computer Science Practice Set 1
Which of the following is false about global variables in Python?
  1. AGlobal immutable variables require global keyword inside function.
  2. BGlobal mutable variables do not require global keyword inside function.
  3. CGlobal keyword is a must for the first time of assignment of a global variable.
  4. DGlobal variables can be accessed any where in the program.
Show answerHide answer

Correct answer: (C) Global keyword is a must for the first time of assignment of a global variable.

Explanation

A variable assigned at the top level of a module is already global, so no global keyword is needed for that first assignment. The keyword is needed only when a function wants to rebind a global name.

Q12DSSSB PGT Computer Science (Technical), 11 Jul 2021
Which one is NOT a feature of Python language?
  1. AHigh level language
  2. BInterpreted language
  3. CCase insensitive
  4. DPortable
Show answerHide answer

Correct answer: (C) Case insensitive

Explanation

Python is case sensitive (Name and name are different variables), so "case insensitive" is not one of its features. It is high-level, interpreted and portable.

Q13DSSSB PGT Computer Science (Technical), 11 Jul 2021
What is the meaning of >>> in Python Language?
  1. A3 left shift
  2. B3 right shift
  3. CInterpreter is ready to take instruction
  4. DCompiler is ready to take instruction
Show answerHide answer

Correct answer: (C) Interpreter is ready to take instruction

Explanation

>>> is the prompt of Python's interactive interpreter (shell), meaning it is ready to accept a statement.

Q14DSSSB PGT Computer Science (Technical), 11 Jul 2021
The given declaration statement in Python Language belongs to which data type? >>> Student = {'SUBJECT' : 'Compiler', 'Marks' : '50', 'Grade' : 'C'}
  1. ANumbers
  2. BSequence
  3. CSets
  4. DDictionary
Show answerHide answer

Correct answer: (D) Dictionary

Explanation

Curly braces holding key : value pairs create a dictionary (dict) in Python.

Q15DSSSB PGT Computer Science (Technical), 11 Jul 2021
Which statement(s) is/are NOT true about the variables in Python Language: I. Values of every variable can be changed once a variable has been created and assigned value. II. Assignment statement is used to create a new variable and assign value.
  1. AOnly I
  2. BOnly II
  3. CBoth I and II
  4. DNeither I nor II
Show answerHide answer

Correct answer: (A) Only I

Explanation

Statement II is true: assignment creates a variable and binds a value. Statement I is treated as not true because a variable can only be rebound; values of immutable objects such as strings and tuples cannot be changed in place.

Q16DSSSB PGT Computer Science (Technical), 11 Jul 2021
What is the output of this code in Python Language: >>> x = 125 >>> y = 13 >>> x //= y >>> x
  1. A9
  2. B125/13
  3. C10
  4. D9.62
Show answerHide answer

Correct answer: (A) 9

Explanation

x //= y is floor division: 125 // 13 = 9 (13 × 9 = 117, remainder 8), so x becomes 9.

Q17DSSSB PGT Computer Science (Technical), 11 Jul 2021
What is output of the code in Python Language: >>> str1 = 'All the Best' >>> str1[-3]
  1. A'l'
  2. B'e'
  3. C'h'
  4. D'B'
Show answerHide answer

Correct answer: (B) 'e'

Explanation

'All the Best' has 12 characters, so index −3 is index 9. Indexes 8-11 are B, e, s, t, so str1[-3] is 'e'.

Q18DSSSB PGT Computer Science (Technical), 11 Jul 2021
Which of the following is NOT a Data MINING Language?
  1. AR. Language
  2. BWeka
  3. CPython
  4. DBASIC
Show answerHide answer

Correct answer: (D) BASIC

Explanation

R, Python and Weka are widely used for data mining. BASIC is an old general-purpose language, not a data mining tool.

Q19DSSSB TGT Computer Science (Technical), 7 Aug 2021, Shift 3
Which of the following combination(s) is/are correct? I. Informative literature – Dictionary II. Creative or imaginative literature – Novels
  1. AOnly I
  2. BOnly II
  3. CBoth I and II
  4. DNeither I nor II
Show answerHide answer

Correct answer: (C) Both I and II

Explanation

Dictionaries are informative literature, and novels are creative or imaginative literature. Both pairs are correct.

Q20DSSSB TGT Computer Science (Technical), 1 Aug 2021, Shift 1
Which of the following acts as an intermediary between the specialist and the expert system?
  1. AKnowledge base
  2. BInference engine
  3. CData dictionary
  4. DKnowledge engineer
Show answerHide answer

Correct answer: (D) Knowledge engineer

Explanation

A knowledge engineer extracts knowledge from the human expert (specialist) and encodes it into the expert system's knowledge base, acting as the intermediary between them.

Q21DSSSB TGT Computer Science, 7 Feb 2024, Shift 2 (12:30 PM)
Which of the following type of function used with strings in the Python language returns the character with the highest ASCII value?
  1. Alen ( )
  2. Bhvalue ( )
  3. Cmax ( )
  4. Dlong ( )
Show answerHide answer

Correct answer: (C) max ( )

Explanation

max() on a string returns the character with the highest ASCII/Unicode value, e.g. max("apple") gives "p". len() gives length; hvalue() and long() are not string functions.

Q22DSSSB TGT Computer Science, 7 Feb 2024, Shift 2 (12:30 PM)
In Python language, which of the following is correct for ‘strip ( )’ function?
  1. AIn returns the string by removing trailing and leading white spaces
  2. BIt returns a list from the string depending upon the delimiter that we specify
  3. CIt returns the power of values passed
  4. DIt returns the string with the first character in upper case and lowering the case for rest of the string
Show answerHide answer

Correct answer: (A) In returns the string by removing trailing and leading white spaces

Explanation

strip() returns a copy of the string with leading and trailing whitespace removed. split() makes a list, capitalize() changes case.

Q23DSSSB TGT Computer Science, 7 Feb 2024, Shift 2 (12:30 PM)
The values in a dictionary can be ______ but the keys in the dictionary should be ______ in Python programming languages
  1. Arepeated, repeated
  2. Brepeated, unique
  3. Cunique, repeated
  4. Dunique, unique
Show answerHide answer

Correct answer: (B) repeated, unique

Explanation

Dictionary values may repeat, but keys must be unique; assigning to an existing key overwrites its value.

Q24DSSSB TGT Computer Science, 7 Feb 2024, Shift 2 (12:30 PM)
______ is a two-dimensional labelled data structure with columns of potentially different type, in data handling with pandas.
  1. ASeries
  2. BMissing data
  3. CIteration
  4. DData frames
Show answerHide answer

Correct answer: (D) Data frames

Explanation

A pandas DataFrame is a two-dimensional labelled data structure whose columns can hold different data types, like a table.

Q25DSSSB TGT Computer Science, 7 Feb 2024, Shift 2 (12:30 PM)
If you encounter an import Error, what does it mean? I. Python could find pandas in list of available libraries II. Pandas couldn’t find python in list of available libraries III. Python couldn’t find Pandas in list of available libraries
  1. AOnly III
  2. BI, II and III
  3. COnly I
  4. DOnly I and III
Show answerHide answer

Correct answer: (A) Only III

Explanation

An ImportError (here ModuleNotFoundError) means Python could not find the pandas module among installed libraries, so only III is correct.

Q26DSSSB TGT Computer Science, 7 Feb 2024, Shift 2 (12:30 PM)
Which of the following is correct for Identifiers name used in Python language?
  1. AAn identifier can have underscore (_) symbol
  2. BWe must use keywords as identifier
  3. CThhere is restriction the length of an identifier
  4. DAn identifier must start with a digit
Show answerHide answer

Correct answer: (A) An identifier can have underscore (_) symbol

Explanation

Python identifiers may contain letters, digits and underscores, so _ is allowed. They cannot start with a digit, cannot be keywords, and have no length limit.

Q27DSSSB TGT Computer Science, 7 Feb 2024, Shift 2 (12:30 PM)
Which of the following symbol is used to add comments in the Python language?
  1. A*
  2. B#
  3. C!
  4. D//
Show answerHide answer

Correct answer: (B) #

Explanation

In Python, # starts a single-line comment; everything after it on that line is ignored.

Q28DSSSB TGT Computer Science, 7 Feb 2024, Shift 2 (12:30 PM)
Extensions like .txt, .py, .CSV, etc in python language are example of ______.
  1. Atext files
  2. Btext editor
  3. CUNI CODE
  4. DASCII
Show answerHide answer

Correct answer: (A) text files

Explanation

Files like .txt, .py and .csv store plain human-readable characters, so they are text files.

Q29DSSSB TGT Computer Science, 7 Feb 2024, Shift 2 (12:30 PM)
Which symbol is used to add the comment in the code or program to make it more readable and understandable in Python programming language?
  1. A#
  2. B*
  3. C–
  4. D:
Show answerHide answer

Correct answer: (A) #

Explanation

Python uses # for comments, which make code more readable and are ignored by the interpreter.

How to use these DSSSB TGT / PGT Computer Science questions

Every question here was asked in a real DSSSB TGT / PGT paper; the paper and shift are shown on the card, and the number opens the question on its own page. Try each one before tapping Show answer, then attempt the full DSSSB TGT / PGT papers as timed tests to check your speed under exam conditions.

More DSSSB TGT / PGT subjects