The document provides a comprehensive overview of key concepts in Python programming, including data types, functions, and object-oriented programming principles. It highlights differences between lists and tuples, Python 2 and 3, and various functions and methods. Additionally, it covers topics such as decorators, virtual environments, and exception handling.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
3 views
Python
The document provides a comprehensive overview of key concepts in Python programming, including data types, functions, and object-oriented programming principles. It highlights differences between lists and tuples, Python 2 and 3, and various functions and methods. Additionally, it covers topics such as decorators, virtual environments, and exception handling.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
What type of programming language is Python?
→ Python is a high-level, interpreted, and dynamically-typed programming
language. What is the difference between list and tuple in Python? → Lists are mutable, while tuples are immutable. What is the purpose of indentation in Python? → Indentation defines code blocks instead of using braces {}. How do you create a virtual environment in Python? → Use python -m venv env_name. What is the difference between is and == in Python? → is checks object identity, while == checks value equality. What is the difference between Python 2 and Python 3? → Python 3 improved Unicode handling, print statements, and integer division. What is the purpose of self in Python classes? → self represents the instance of the class. What is the difference between deepcopy() and copy()? → copy() creates a shallow copy, while deepcopy() creates an independent copy of nested objects. What is a Python decorator? → A function that modifies another function’s behavior without modifying its code. What is the difference between @staticmethod and @classmethod? → @staticmethod doesn’t use class or instance data, while @classmethod takes the class as its first argument. What is Python’s garbage collection mechanism? → Python uses reference counting and a cyclic garbage collector. What is a lambda function in Python? → A small anonymous function using the lambda keyword. What is the difference between append() and extend() in Python lists? → append() adds a single element, while extend() merges another iterable. How do you check the Python version installed? → Use python --version or sys.version. What is the purpose of the with statement in Python? → It simplifies resource management by automatically closing files or releasing resources. What is a generator in Python? → A function that yields values lazily using the yield keyword. What is the difference between range() and xrange()? → xrange() existed in Python 2 and returned a generator, while range() in Python 3 behaves like xrange(). What is the difference between mutable and immutable types in Python? → Mutable types (lists, dictionaries) can be modified, while immutable types (tuples, strings) cannot. What is the purpose of if __name__ == "__main__": in Python? → It ensures that a script runs only when executed directly, not when imported. What is the difference between *args and **kwargs? → *args collects positional arguments, while **kwargs collects keyword arguments. What is the difference between split() and join() in Python? → split() breaks a string into a list, while join() merges a list into a string. What is the difference between del, pop(), and remove()? → del removes an item by index, pop() removes and returns an item, and remove() deletes an item by value. What is the purpose of dir() in Python? → It lists all attributes and methods of an object. What is the difference between any() and all() functions? → any() returns True if at least one element is True, while all() returns True only if all elements are True. How do you handle exceptions in Python? → Using try, except, finally, and else blocks. What is the difference between global and nonlocal keywords? → global modifies global variables, while nonlocal modifies variables in an enclosing function. What is monkey patching in Python? → Modifying or replacing methods at runtime. What is the purpose of the pass statement? → It acts as a placeholder for future code. What is the difference between Python arrays and lists? → Lists can hold mixed data types, while arrays (from array module) store only one type. What is Python’s __init__.py file used for? → It marks a directory as a Python package.