0% found this document useful (0 votes)
6 views4 pages

Python Viva Differences CheatSheet

The document outlines key differences between various Python concepts, including data types (List vs Tuple), comparison operators ('is' vs '=='), and programming constructs (for loop vs while loop). It also explains object-oriented principles such as inheritance, encapsulation, and the distinctions between class and instance variables. Additionally, it covers error handling, copying methods, and the differences between abstract classes and interfaces.

Uploaded by

sumitcode111
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Python Viva Differences CheatSheet

The document outlines key differences between various Python concepts, including data types (List vs Tuple), comparison operators ('is' vs '=='), and programming constructs (for loop vs while loop). It also explains object-oriented principles such as inheritance, encapsulation, and the distinctions between class and instance variables. Additionally, it covers error handling, copying methods, and the differences between abstract classes and interfaces.

Uploaded by

sumitcode111
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Python Viva: All 'Difference Between' Questions

List vs Tuple
- List: Mutable, uses [], slower
- Tuple: Immutable, uses (), faster

'is' vs '=='
- 'is': Compares memory location (object identity)
- '==': Compares values

Python vs Java
- Python: Interpreted, dynamically typed, short syntax
- Java: Compiled, statically typed, verbose

break vs continue
- break: Exits the loop completely
- continue: Skips current iteration, continues loop

Mutable vs Immutable
- Mutable: Can be changed (e.g. list, dict)
- Immutable: Cannot be changed (e.g. int, str, tuple)

Function vs Method
- Function: Independent block of code
- Method: Associated with object/class

for loop vs while loop


- for loop: Used with fixed iterations/range
- while loop: Runs while a condition is true

Global vs Local Variable


- Global: Defined outside function, accessible everywhere
- Local: Defined inside function, accessible only there

Compiler vs Interpreter
- Compiler: Converts whole code at once
- Interpreter: Converts code line by line (Python uses this)

append() vs extend()
- append(): Adds one element
- extend(): Adds multiple elements from iterable

Set vs Dictionary
- Set: Unique values, no keys
- Dictionary: Key-value pairs

Deep Copy vs Shallow Copy


- Shallow Copy: References nested objects
- Deep Copy: Full independent object copy

range() vs xrange()
- range(): Returns list (Python 2), generator (Python 3)
- xrange(): Only in Python 2, memory efficient

input() vs raw_input()
- input(): Evaluates input (Python 2), returns string (Python 3)
- raw_input(): Returns string (Python 2)

del vs remove()
- del: Deletes by index
- remove(): Deletes by value

@staticmethod vs @classmethod
- staticmethod: No self/cls, utility functions
- classmethod: Uses cls, affects class-level data

len() vs __len__()
- len(): Built-in function
- __len__(): Internal method for len()

Error vs Exception
- Error: Critical, system-related
- Exception: Handled via try-except

Tuple vs String
- Tuple: Collection of values (any type)
- String: Sequence of characters only

Compilation Error vs Runtime Error


- Compilation Error: Before execution (syntax)
- Runtime Error: During execution (e.g. division by zero)

Class vs Object
- Class: Blueprint
- Object: Instance of a class

Inheritance vs Encapsulation
- Inheritance: Reusability of code
- Encapsulation: Data hiding using access modifiers

Overloading vs Overriding
- Overloading: Same method name, diff args (not direct in Python)
- Overriding: Redefining method in subclass

Encapsulation vs Abstraction
- Encapsulation: Hides data using private vars
- Abstraction: Hides implementation using abstract classes

Public vs Private vs Protected


- Public: Accessible everywhere
- Protected: Accessible in class & subclass (_var)
- Private: Accessible only in class (__var)

Constructor vs Method
- Constructor: __init__, auto-called when object created
- Method: Normal function inside class, called explicitly

Abstract Class vs Interface


- Abstract Class: Can have concrete methods, use ABC
- Interface: Not a separate concept in Python

Single vs Multiple Inheritance


- Single: One base class
- Multiple: Multiple base classes

is-a vs has-a
- is-a: Inheritance (Dog is-a Animal)
- has-a: Composition (Car has-a Engine)
Class Variable vs Instance Variable
- Class Variable: Shared across all objects
- Instance Variable: Unique to each object

You might also like