Variables, Types & Operators questions and answers
Dynamic typing, numbers, operators, precedence and truthiness. Practise variables, types & operators questions from the python section of placement tests, with a worked explanation after every answer. Practice is free and needs no sign-up.
Sample variables, types & operators questions with worked answers
Question 1
Which of the following is a valid Python variable name?
- 2nd_rank
- total-marks
- class
- _score2
Answer: D. _score2
Explanation: A name may contain letters, digits and underscores but cannot start with a digit, so _score2 is valid. 2nd_rank starts with a digit, total-marks contains a minus sign, and class is a reserved keyword.
Question 2
Which statement about the operators == and is is correct?
- == compares the values of two objects, while is checks whether both names refer to the same object
- is compares the values of two objects, while == checks whether both names refer to the same object
- Both give the same result for any two lists that have equal contents
- is can be used only with numbers, while == works with every type
Answer: A. == compares the values of two objects, while is checks whether both names refer to the same object
Explanation: == asks whether two objects are equal in value; is asks whether they are one and the same object in memory. Two separately built lists with equal contents are == but not is.
Question 3
Booleans are used in arithmetic here. What does the snippet print?
print(True + True * 2, isinstance(True, int))
- 4 True
- 3 True
- 3 False
- TypeError
Answer: B. 3 True
Explanation: bool is a subclass of int, with True equal to 1, so isinstance(True, int) is True. Multiplication comes first: True * 2 = 2, then True + 2 = 3.
All 20 variables, types & operators questions with answers
- The name x is first bound to a number and then to text. What does this snippet…
- Riya shares 17 chocolates equally among 5 friends and keeps the leftovers…
- A roll number typed as text is converted before adding. What is printed?
- Which of the following is a valid Python variable name?
- Which operator raises a number to a power in Python?
- Applying the usual operator precedence, what does this arithmetic expression…
- An integer is added to a float. What does Python print for the sum?
- Floor division and remainder are applied to a negative number. What is the…
- Unary minus meets the power operator, with and without brackets. What does…
- How many values in the list vals are treated as true by the if test?
- A voter-age check uses chained comparisons. What does it print for age 21?
- Two separate lists hold the same values and a third name points to the first…
- Python 3's round() is called on two values that end in .5. What does this print?
- A string holding a decimal number is passed straight to int(). What is the…
- Which statement about the operators == and is is correct?
- Booleans are used in arithmetic here. What does the snippet print?
- Floor division by a float and a remainder with a negative divisor are printed…
- Five different operators appear in one expression. Following precedence rules…
- A float product is compared with 0.3 in two ways. What does this print?
- Three type conversions are printed on one line. What is the output?
Variables, Types & Operators: common questions
What are variables, types & operators questions?
Dynamic typing, numbers, operators, precedence and truthiness. They appear in the python section of many placement tests.
Where can I practise variables, types & operators questions with answers for free?
Right here on LogicWiz Exams. Every variables, types & operators question has a worked explanation after you answer. Practice is free and needs no sign-up.
How should I practise variables, types & operators?
Start with easy questions, then move to medium and hard. Read the explanation after each answer, and come back to the ones you missed.
Start practising
On this page you can start a fresh set of variables, types & operators questions, choose easy, medium or hard, and time yourself if you want to. Or practise the whole subject: Python practice.
More python topics
- Python Strings: Indexing, slicing, methods, formatting and immutability.
- Lists & Tuples: Slicing, methods, copies, sorting and unpacking.
- Dictionaries & Sets: Lookups, iteration, hashable keys and set operations.
- Conditions & Loops: if/elif, for, while, range, break, continue and loop else.
- Functions & Scope: Arguments, defaults, *args, closures, lambda and recursion.
- Comprehensions & Generators: List, dict and set comprehensions, yield and lazy evaluation.
- Classes & Objects: Attributes, inheritance, super(), dunder methods and properties.
- Exceptions & Files: try/except/else/finally, raising errors and the with statement.
- Built-ins & Standard Library: sorted, zip, any/all, collections, itertools and imports.
Other subjects
- Quantitative Aptitude: Arithmetic, percentages, time and work, speed, probability and data interpretation: the numerical section of every fresher test.
- Logical Reasoning: Series, coding-decoding, arrangements, syllogisms and puzzles: the section that separates prepared candidates from the rest.
- Verbal Ability: Vocabulary, grammar, reading comprehension and sentence order: tested in nearly every IT services hiring exam.
- Technical & Programming: CS fundamentals, output prediction and pseudo-code: the technical MCQ round for IT roles.
- SQL: SQL quizzes by topic, from SELECT and joins to window functions: query output and concepts for analyst and developer roles.
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge · Test from a job description · LogicWiz Open: free team quiz · Free interview prep