PyData Careers
21.2K subscribers
247 photos
11 videos
26 files
416 links
Python Data Science jobs, interview tips, and career insights for aspiring professionals.

Admin: @HusseinSheikho || @Hussein_Sheikho
Download Telegram
This media is not supported in your browser
VIEW IN TELEGRAM
โค1๐Ÿ‘1๐Ÿ”ฅ1
0013)
Anonymous Quiz
19%
1
38%
2
31%
3
11%
4
Follow me on linkedin (important for you)

https://www.linkedin.com/in/hussein-sheikho-4a8187246
๐Ÿ”ฅ1
๐ŸŸฉ Whatโ€™s the question?
Youโ€™ve created a Python module (a .py file) with several functions,
but you donโ€™t want all of them to be available when someone imports the module using from mymodule import *.

For example:

# mymodule.py
def func1():
pass

def func2():
pass

def secret_func():
pass


Now, if someone writes:

from mymodule import *


๐Ÿ”ป All three functions will be imported โ€” but you want to hide secret_func.

โœ… So whatโ€™s the solution?
You define a list named __all__ that only contains the names of the functions you want to expose:

__all__ = ['func1', 'func2']


Now if someone uses:

from mymodule import *


Theyโ€™ll get only func1 and func2. The secret_func stays hidden ๐Ÿ”’

๐ŸŸก In sall __all__ list controls what gets imported when someone uses import *.
Everything not listed stays out โ€” though itโ€™s still accessible manually if someone knows the name.

If this was confusing or you want a real example with output, just ask, my friend ๐Ÿ’กโค๏ธ

#Python #PythonTips #CodeClean #ImportMagic


๐Ÿ”By: https://t.me/DataScienceQ
๐Ÿ‘6โค1๐Ÿฅฐ1
This media is not supported in your browser
VIEW IN TELEGRAM
โค2
0014)
Anonymous Quiz
29%
1
19%
2
22%
3
30%
4
๐Ÿ Python Tip of the Day: Decorators โ€” Enhance Function Behavior โœจ

๐Ÿง  What is a Decorator in Python?
A decorator lets you wrap extra logic before or after a function runs, without modifying its original code.

๐Ÿ”ฅ A Simple Example

Imagine you have a basic greeting function:

def say_hello():
print("Hello!")


You want to log a message before and after it runs, but you donโ€™t want to touch say_hello() itself. Hereโ€™s where a decorator comes in:

def my_decorator(func):
def wrapper():
print("Calling the function...")
func()
print("Function has been called.")
return wrapper


Now โ€œdecorateโ€ your function:

@my_decorator
def say_hello():
print("Hello!")


When you call it:

say_hello()


Output:
Calling the function...
Hello!
Function has been called.




๐Ÿ’ก Quick Tip:
The @my_decorator syntax is just syntactic sugar for:
s
ay_hello = my_decorator(say_hello)

๐Ÿš€ Why Use Decorators?
- ๐Ÿ”„ Reuse common โ€œbefore/afterโ€ logic
- ๐Ÿ”’ Keep your original functions clean
- ๐Ÿ”ง Easily add logging, authentication, timing, and more



#PythonTips #Decorators #AdvancedPython #CleanCode #CodingMagic

๐Ÿ”By: https://t.me/DataScienceQ
๐Ÿ‘5๐Ÿ”ฅ2
This media is not supported in your browser
VIEW IN TELEGRAM
0015)
Anonymous Quiz
34%
1
45%
2
15%
3
7%
4
๐Ÿง  What is a Generator in Python?
A generator is a special type of iterator that produces values lazilyโ€”one at a time, and only when neededโ€”without storing them all in memory.

---

โ“ How do you create a generator?
โœ… Correct answer:
Option 1: Use the yield keyword inside a function.

๐Ÿ”ฅ Simple example:

def countdown(n):
while n > 0:
yield n
n -= 1


When you call this function:

gen = countdown(3)
print(next(gen)) # 3
print(next(gen)) # 2
print(next(gen)) # 1


Each time you call next(), the function resumes from where it left off, runs until it hits yield, returns a value, and pauses again.

---

โ›” Why are the other options incorrect?

- Option 2 (class with __iter__ and __next__):
It works, but itโ€™s more complex. Using yield is simpler and more Pythonic.

- Options 3 & 4 (for or while loops):
Loops are not generators themselves. They just iterate over iterables.

---

๐Ÿ’ก Pro Tip:
Generators are perfect when working with large or infinite datasets. Theyโ€™re memory-efficient, fast, and clean to write.

---

๐Ÿ“Œ #Python #Generator #yield #AdvancedPython #PythonTips #Coding


๐Ÿ”By: https://t.me/DataScienceQ
๐Ÿ‘6โค2๐Ÿ”ฅ2โคโ€๐Ÿ”ฅ1
This media is not supported in your browser
VIEW IN TELEGRAM
โค1โคโ€๐Ÿ”ฅ1๐Ÿ’‹1
๐Ÿ”ฅ1
0016)
Anonymous Quiz
65%
1
18%
2
15%
3
2%
4
๐Ÿฅฐ1
๐ŸŽฏ Python Quick Quiz โ€“ OOP Edition
๐Ÿ’ก _What is the primary use of the __init__ method in a Python class?_

๐Ÿ”˜ Option 1: Initializing class attributes โœ…
๐Ÿ”˜ Option 2: Defining class methods
๐Ÿ”˜ Option 3: Inheriting from a superclass
๐Ÿ”˜ Option 4: Handling exceptions

๐Ÿง  Correct Answer: Option 1
๐Ÿ“Œ The init method is a special method used to initialize the objectโ€™s attributes when a class is instantiated. It's like a constructor in other programming languages.
class Person:
def __init__(self, name, age):
self.name = name
self.age = age

john = Person("John", 25)
print(john.name) # Output: John


#PythonTips #OOP #PythonQuiz #CodingCommunity

๐ŸŽจhttps://t.me/DataScienceQ
๐Ÿ”ฅ4โค2
This media is not supported in your browser
VIEW IN TELEGRAM
๐Ÿ”ฅ2
0017)
Anonymous Quiz
24%
1
34%
2
13%
3
29%
4
๐Ÿ”ฅ1