Python | Algorithms | Data Structures | Cyber ​​Security | Networks
38.6K subscribers
778 photos
23 videos
21 files
713 links
This channel is for Programmers, Coders, Software Engineers.

1) Python
2) django
3) python frameworks
4) Data Structures
5) Algorithms
6) DSA

Admin: @Hussein_Sheikho

Ad & Earn money form your channel:
https://telega.io/?r=nikapsOH
Download Telegram
Top 100 Python Interview Questions & Answers

#Python #InterviewQuestions #CodingInterview #Programming #PythonDeveloper

👇👇👇👇
Please open Telegram to view this post
VIEW IN TELEGRAM
1
Top 100 Python Interview Questions & Answers

#Python #InterviewQuestions #CodingInterview #Programming #PythonDeveloper

Part 1: Core Python Fundamentals (Q1-20)

#1. Is Python a compiled or an interpreted language?
A: Python is an interpreted language. The Python interpreter reads and executes the source code line by line, without requiring a separate compilation step. This makes development faster but can result in slower execution compared to compiled languages like C++.

#2. What is the GIL (Global Interpreter Lock)?
A: The GIL is a mutex (a lock) that allows only one thread to execute Python bytecode at a time within a single process. This means even on a multi-core processor, a single Python process cannot run threads in parallel. It simplifies memory management but is a performance bottleneck for CPU-bound multithreaded programs.

#3. What is the difference between Python 2 and Python 3?
A: Key differences include:
print: In Python 2, print is a statement (print "hello"). In Python 3, it's a function (print("hello")).
Integer Division: In Python 2, 5 / 2 results in 2 (floor division). In Python 3, it results in 2.5 (true division).
Unicode: In Python 3, strings are Unicode (UTF-8) by default. In Python 2, you had to explicitly use u"unicode string".

#4. What are mutable and immutable data types in Python?
A:
Mutable: Objects whose state or contents can be changed after creation. Examples: list, dict, set.
Immutable: Objects whose state cannot be changed after creation. Examples: int, float, str, tuple, frozenset.

# Mutable example
my_list = [1, 2, 3]
my_list[0] = 99
print(my_list)

[99, 2, 3]


#5. How is memory managed in Python?
A: Python uses a private heap to manage memory. A built-in garbage collector automatically reclaims memory from objects that are no longer in use. The primary mechanism is reference counting, where each object tracks the number of references to it. When the count drops to zero, the object is deallocated.

#6. What is the difference between is and ==?
A:
== (Equality): Checks if the values of two operands are equal.
is (Identity): Checks if two variables point to the exact same object in memory.

list_a = [1, 2, 3]
list_b = [1, 2, 3]
list_c = list_a

print(list_a == list_b) # True, values are the same
print(list_a is list_b) # False, different objects in memory
print(list_a is list_c) # True, same object in memory

True
False
True


#7. What is PEP 8?
A: PEP 8 (Python Enhancement Proposal 8) is the official style guide for Python code. It provides conventions for writing readable and consistent Python code, covering aspects like naming conventions, code layout, and comments.

#8. What is the difference between a .py and a .pyc file?
A:
.py: This is the source code file you write.
.pyc: This is the compiled bytecode. When you run a Python script, the interpreter compiles it into bytecode (a lower-level, platform-independent representation) and saves it as a .pyc file to speed up subsequent executions.

#9. What are namespaces in Python?
A: A namespace is a system that ensures all names in a program are unique and can be used without conflict. It's a mapping from names to objects. Python has different namespaces: built-in, global, and local.