Python Basics— Concepts, Formulas & Shortcuts
- Immutable types: int, float, str, tuple, frozenset. Mutable: list, dict, set.
- Variables are names bound to objects, not boxes holding values — assignment rebinds the name.
- Lists are mutable and use []; tuples are immutable and use (); tuples can be dictionary keys, lists cannot.
- "is" compares identity (same object); "==" compares value.
- Default mutable arguments are created ONCE at function definition — the classic def f(x, lst=[]) bug.
- Indentation is syntax in Python, not style — inconsistent indentation is a runtime error, not a warning.
Python Basics Practice Questions with Answers
Attempt each question first, then open the explanation. All 8 questions below are free to read and require no signup.
Q1.Which of these Python types is immutable?
Easy- Alist
- Bdict
- Ctuple
- Dset
Python Basics question 1 of 8+Show Answer & Explanation
Answer: C. tuple
Explanation: Tuples cannot be modified after creation. Lists, dicts and sets are all mutable.
Q2.What is the output of: print(type([]))
Easy- A<class 'list'>
- B<class 'tuple'>
- C<class 'array'>
- DError
Python Basics question 2 of 8+Show Answer & Explanation
Answer: A. <class 'list'>
Explanation: [] creates an empty list, so type() reports <class 'list'>.
Q3.What does the expression 7 // 2 evaluate to in Python 3?
Easy- A3.5
- B3
- C4
- D3.0
Python Basics question 3 of 8+Show Answer & Explanation
Answer: B. 3
Explanation: // is floor division on integers, giving the integer 3. Use / for true division, which returns 3.5.
Q4.What is the output of: print("Python"[-2:])
Moderate- Aon
- Bho
- CPy
- Dthon
Python Basics question 4 of 8+Show Answer & Explanation
Answer: A. on
Explanation: Negative indexing starts from the end, so [-2:] returns the last two characters, "on".
Q5.What does "is" compare in Python?
Moderate- AValues
- BObject identity (memory address)
- CTypes only
- DString content
Python Basics question 5 of 8+Show Answer & Explanation
Answer: B. Object identity (memory address)
Explanation: "is" checks whether both names refer to the same object; "==" checks value equality.
Q6.What is the result of: len({1, 2, 2, 3, 3, 3})
Easy- A3
- B4
- C6
- DError
Python Basics question 6 of 8+Show Answer & Explanation
Answer: A. 3
Explanation: A set stores only distinct elements, so duplicates collapse and the length is 3.
Q7.What is the output of: def f(x, lst=[]): lst.append(x); return lst — calling f(1) then f(2)?
Difficult- A[1] then [2]
- B[1] then [1, 2]
- C[1, 2] then [1, 2]
- DError
Python Basics question 7 of 8+Show Answer & Explanation
Answer: B. [1] then [1, 2]
Explanation: The default list is created once at function definition and is shared across calls, so the second call returns [1, 2]. Use lst=None as the fix.
Q8.Which keyword is used to define an anonymous function in Python?
Easy- Adef
- Blambda
- Cfunc
- Danon
Python Basics question 8 of 8+Show Answer & Explanation
Answer: B. lambda
Explanation: lambda creates a small anonymous function, e.g. square = lambda x: x * x.
Python Basics — Frequently Asked Questions
What is the difference between a list and a tuple?+
A list is mutable, slightly larger in memory and cannot be used as a dictionary key. A tuple is immutable, marginally faster to iterate and hashable, so it can be a dict key or set element.
What does "is" do differently from "=="?+
"is" checks whether two names refer to the same object in memory; "==" checks whether the values are equal. Two separate lists with identical contents are == but not is.
Cleared the aptitude round? Now grab the role.
Preparation only pays off when you apply. Thousands of internships and fresher jobs across India are live on MyInternships.in right now — free to apply, no consultancy fees.
