Code With Python
39K subscribers
841 photos
24 videos
22 files
746 links
This channel delivers clear, practical content for developers, covering Python, Django, Data Structures, Algorithms, and DSA – perfect for learning, coding, and mastering key programming skills.
Admin: @HusseinSheikho || @Hussein_Sheikho
Download Telegram
πŸ“š The Python Interview Handbook 2023 (2023)

1⃣ Join Channel Download:
https://t.me/+MhmkscCzIYQ2MmM8

2⃣ Download Book: https://t.me/c/1854405158/671

πŸ’¬ Tags: #python #Interview

USEFUL CHANNELS FOR YOU
πŸ‘31
πŸ“š CRACKING the CODING INTERVIEW (2023)

1⃣ Join Channel Download:
https://t.me/+MhmkscCzIYQ2MmM8

2⃣ Download Book: https://t.me/c/1854405158/673

πŸ’¬ Tags: #INTERVIEW

USEFUL CHANNELS FOR YOU
πŸ‘32❀6
Ace the Python Coding Interview

Python is a high level, dynamically typed, and object-oriented language that is easy to read and write. It has a large, supportive community of developers that contribute to its development and support. Python's simplicity, flexibility, and versatility make it a perfect choice in the industry. This Skill Path will take you through all that you need to know to crack your Python interviews with confidence. You’ll cover everything from data structures to object-oriented design and concurrency. You will also get to know the essential patterns behind popular coding interview questions. By the time you’re done, your skills will be polished to ace the interview of any company.


Link: https://www.educative.io/path/ace-python-coding-interview?aff=KQEy

#python #coding #interview

πŸ‘‰ BEST DATA SCIENCE CHANNELS ON TELEGRAM πŸ‘ˆ
πŸ‘6❀2
Forwarded from PyData Careers
❔ Interview Question

What is the difference between __str__ and __repr__ methods in Python classes, and when would you implementstr
__str__ returns a human-readable string representation of an object (e.g., via print(obj)), making it user-friendly for displayrepr__repr__ aims for a more detailed, unambiguous string that's ideally executable as code (like repr(obj)), useful for debuggingβ€”imstr __str__ for end-user outrepr__repr__ for developer tools or str __str__ is defined.

tags: #interview #python #magicmethods #classes

➑️ @DataScienceQ 🀎
Please open Telegram to view this post
VIEW IN TELEGRAM
❀1
❔ Interview Question

What is the potential pitfall of using a mutable object (like a list or dictionary) as a default argument in a Python function?

Answer: A common pitfall is that the default argument is evaluated only once, when the function is defined, not each time it is called. If that default object is mutable, any modifications made to it in one call will persist and be visible in subsequent calls.

This can lead to unexpected and buggy behavior.

Incorrect Example (The Pitfall):

def add_to_list(item, my_list=[]):
my_list.append(item)
return my_list

# First call seems to work fine
print(add_to_list(1)) # Output: [1]

# Second call has unexpected behavior
print(add_to_list(2)) # Output: [1, 2] -- The list from the first call was reused!

# Third call continues the trend
print(add_to_list(3)) # Output: [1, 2, 3]


The Correct, Idiomatic Solution:

The standard practice is to use None as the default and create a new mutable object inside the function if one isn't provided.

def add_to_list_safe(item, my_list=None):
if my_list is None:
my_list = [] # Create a new list for each call
my_list.append(item)
return my_list

# Each call now works independently
print(add_to_list_safe(1)) # Output: [1]
print(add_to_list_safe(2)) # Output: [2]
print(add_to_list_safe(3)) # Output: [3]


tags: #Python #Interview #CodingInterview #PythonTips #Developer #SoftwareEngineering #TechInterview

━━━━━━━━━━━━━━━
By: @DataScience4 ✨
❀2
❔ Interview question

How do you create a new directory using the os module in Python, and what is the recommended way to handle cases where the directory might already exist?

Answer: The primary function to create a new directory (and any necessary parent directories) is os.makedirs(). To gracefully manage situations where the target directory might already exist without causing a FileExistsError, the recommended approach is to set the exist_ok parameter to True. This ensures that if the directory already exists, no exception is raised, allowing your program to continue execution smoothly. An example usage would be os.makedirs('path/to/my/new_directory', exist_ok=True).

tags: #interview #os #PythonBasics #FileSystem

━━━━━━━━━━━━━━━
By: @DataScience4 ✨