Python Variables and Data Types - Complete
Question Answers
Q. What is a Variable in Python?
A variable is a named memory location used to store data. Example: x=10.
Q. Rules for Naming Variables
Must start with letter or _, cannot start with digit, keywords not allowed, case-sensitive.
Q. What is Dynamic Typing?
Python automatically determines the data type at runtime.
Q. Multiple Variable Assignment
a,b,c=10,20,30 and x=y=z=100.
Q. Local vs Global Variable
Local variables exist inside functions. Global variables exist outside functions.
Q. What is Variable Scope?
Scope defines where a variable can be accessed.
Q. What is a Data Type?
A data type defines the kind of value a variable stores.
Q. Numeric Data Types
int, float, complex.
Q. Boolean Data Type
Stores True or False.
Q. String Data Type
Sequence of characters enclosed in quotes.
Q. List Data Type
Ordered, mutable collection.
Q. Tuple Data Type
Ordered, immutable collection.
Q. Dictionary Data Type
Stores key-value pairs.
Q. Set Data Type
Unordered collection of unique values.
Q. List vs Tuple
List is mutable; Tuple is immutable.
Q. Mutable vs Immutable
Mutable: list, dict, set. Immutable: int, float, str, tuple.
Q. Deep Q: Why Dynamic Typing?
Types are decided at runtime.
Q. Deep Q: Variable vs Object
Variable is a reference; object is actual data.
Q. Deep Q: Why Strings Immutable?
Improves security, optimization, and performance.
Q. Deep Q: Why Tuples Faster?
Because they are immutable and use less memory.
Q. Deep Q: == vs is
== compares values; is compares object identity.
Q. Deep Q: Memory Management
Python uses references and garbage collection.