Python Literals — Python Technical Interview Questions & Answers
Python Literals
Python Literals
- A literal is a value you write as-is in the source. 10 is an int literal. 3.14 is float. "Asha" is a string. True and False are booleans. None means no value. You are not computing them — you are writing the value itself.
- Collections have literals too: [1, 2] list, (1, 2) tuple, {1, 2} set, {"name": "Asha"} dict. 2+3j is a complex literal. Interviewers want one example each: int, str, bool, None. That is enough.
- Python Literals — output: 10, Asha, True, None. Four real literals.
Technical Interview Tip: One example each: int, str, bool, None.
Code Examples for Python Literals
Example
# Literals
print(10)
print("Asha")
print(True)
print(None)
Python Literals — output: 10, Asha, True, None. Four real literals.
How to Explain Python Literals to an Interviewer
Explain Literals as if you are teaching a junior — definition, then one tiny script.
Fixed value written in code. 10, "hi", True, None.
What does the example print, and why?
Python Literals — output: 10, Asha, True, None
What mistake do freshers make with Literals?
List/dict literals too.