Python Data Science Jobs & Interviews
18.7K subscribers
148 photos
3 videos
17 files
259 links
Your go-to hub for Python and Data Science—featuring questions, answers, quizzes, and interview tips to sharpen your skills and boost your career in the data-driven world.

Admin: @Hussein_Sheikho
Download Telegram
Python Data Science Jobs & Interviews
class Person:     population = 0     def init(self, name):         self.name = name         Person.population += 1     @classmethod     def from_birth_year(cls, name, birth_year):         age = 2024 - birth_year         instance = cls(name)        …
1⃣ A Person class is defined with an init method and a class variable population.

2⃣ The from_birth_year method is defined using the @classmethod decorator. This method is an alternative constructor that calculates the person's age based on their birth year and creates a new instance of the Person class.

3⃣ The get_population method is also defined using @classmethod, which returns the population count (the number of instances created from the Person class).

4⃣ Two instances of the Person class are created: one using the default constructor and the other using the alternative constructor from_birth_year.

5⃣ The information of the instances and the population count are printed.

The classmethod function allows you to define methods that operate on the class itself and can access class variables and methods, rather than operating on individual instances.


https://t.iss.one/DataScienceQ
👍1
Python Data Science Jobs & Interviews
Question 54: #python
What is the purpose of the 'classmethod' decorator in Python?
❤️ The classmethod function in Python is used to define a method that operates on the class itself rather than on its instances.

❤️ This type of method automatically receives the class as its first argument, commonly named cls, instead of the instance.

❤️ This type of method is useful for defining alternative constructors, accessing class-level variables, or performing operations related to the class itself.
1
Python Data Science Jobs & Interviews
Question 55: #python
What is the purpose of the 'is' operator in Python?
# Define two identical lists
list1 = [1, 2, 3]
list2 = [1, 2, 3]

# Define another list that refers to the first list
list3 = list1

# Comparison using 'is'
print(list1 is list2) # Output: False
print(list1 is list3) # Output: True

# Comparison using '=='
print(list1 == list2) # Output: True
print(list1 == list3) # Output: True



https://t.iss.one/DataScienceQ
2👍1
Python Data Science Jobs & Interviews
# Define two identical lists list1 = [1, 2, 3] list2 = [1, 2, 3] # Define another list that refers to the first list list3 = list1 # Comparison using 'is' print(list1 is list2) # Output: False print(list1 is list3) # Output: True …
1⃣ Two lists, list1 and list2, are defined with identical values but refer to different memory locations.

2⃣ Another list, list3, is defined which refers to list1, so both refer to the same memory location.

3⃣ When list1 and list2 are compared using the is operator, the result is False because these two lists refer to different memory locations.

4⃣ When list1 and list3 are compared using the is operator, the result is True because both refer to the same memory location.

5⃣ Comparison using == for list1 and list2 results in True because the values inside the lists are identical.

The is operator is used to check the identity of objects, while the == operator is used to check the equality of values.


https://t.iss.one/DataScienceQ
2👍1
Python Data Science Jobs & Interviews
Question 55: #python
What is the purpose of the 'is' operator in Python?
❤️ The is operator in Python is used to compare two objects to determine if they have the same identity, i.e., if they refer to the same memory location.

❤️ This operator evaluates to True if the objects have the same identity and False otherwise.


https://t.iss.one/DataScienceQ
5👍1
Forwarded from ُEng. Hussein Sheikho
🔍 Join us for an in-depth exploration of GPT-4o, the latest advancement in OpenAI’s language models.

✔️ This event is designed to provide you with valuable insights and practical knowledge to enhance your AI skill.

In this session, we will guide you through:

1️⃣ Introduction to GPT-4o.
2️⃣ Utilizing GPT-4o with APIs.
3️⃣ Exploring GPT-4o's Vision Capabilities.
4️⃣ Building AI Applications with GPT-4o.


😀 Register Here for Free:
https://www.buildfastwithai.com/events/gpt-4o-deep-dive
Please open Telegram to view this post
VIEW IN TELEGRAM
1👍1
Python Data Science Jobs & Interviews
Question 56: #python
What is the purpose of the 'pass' statement in Python?
class MyClass:
def method_not_implemented_yet(self):
pass # This method is not yet implemented

# Define a function that is not yet implemented
def my_function():
pass # This function is not yet implemented

# Use pass in a loop
for i in range(5):
if i == 3:
pass # We could perform an action here, but currently we do nothing
print(I)


https://t.iss.one/DataScienceQ
1
Python Data Science Jobs & Interviews
class MyClass: def method_not_implemented_yet(self): pass # This method is not yet implemented # Define a function that is not yet implemented def my_function(): pass # This function is not yet implemented # Use pass in…
1⃣ A class MyClass is defined with a method method_not_implemented_yet that is not yet implemented and uses pass.

2⃣ A function my_function is defined that is not yet implemented and uses pass.

3⃣ In a for loop, when the value of i is 3, pass is used to indicate that no action is taken in this case, but the loop continues its execution.

The pass statement allows you to maintain the structure of your code without syntactic errors, even if some parts of the code are not yet implemented.


https://t.iss.one/DataScienceQ
1👍1
Python Data Science Jobs & Interviews
Question 57: #python
What is the purpose of the 'del' statement in Python?
# Deleting a variable
x = 10
print(x) # Output: 10
del x
# print(x) # This line will cause an error because x has been deleted

# Deleting an element from a list by its index
my_list = [1, 2, 3, 4, 5]
del my_list[2]
print(my_list) # Output: [1, 2, 4, 5]

# Deleting a slice from a list
my_list = [1, 2, 3, 4, 5]
del my_list[1:3]
print(my_list) # Output: [1, 4, 5]

# Deleting an attribute from an object
class MyClass:
def init(self):
self.attr1 = "value1"
self.attr2 = "value2"

obj = MyClass()
print(obj.attr1) # Output: value1
del obj.attr1
# print(obj.attr1) # This line will cause an error because attr1 has been deleted




ttps://t.iss.one/DataScienceQ
🔥4
Python Data Science Jobs & Interviews
# Deleting a variable x = 10 print(x) # Output: 10 del x # print(x) # This line will cause an error because x has been deleted # Deleting an element from a list by its index my_list = [1, 2, 3, 4, 5] del my_list[2] print(my_list) # Output: [1…
1⃣ A variable x is defined and then deleted using del.

2⃣ An element from the list my_list is deleted using its index.

3⃣ A slice from the list my_list is deleted using del.

4⃣An attribute attr1 from the object obj of the class MyClass is deleted.

The del statement allows you to remove unnecessary variables, items, and attributes from memory, which can help in memory management and optimizing the performance of your program.



https://t.iss.one/DataScienceQ
👍21
Python Data Science Jobs & Interviews
Question 57: #python
What is the purpose of the 'del' statement in Python?
❤️The del statement in Python is used to delete a variable, an item from a list, or a slice from a list.

❤️This statement frees the memory space occupied by the variable or item, allowing it to be reclaimed by the system.

❤️Additionally, it can be used to delete attributes from objects and elements from lists.


https://t.iss.one/DataScienceQ
👍1
Python Data Science Jobs & Interviews
Question 58: #python
What is the purpose of the 'with' statement in Python?
# Using 'with' statement to open and automatically close a file
with open('example.txt', 'w') as file:
file.write('Hello, World!')

# Reading from the file
with open('example.txt', 'r') as file:
content = file.read()
print(content)



https://t.iss.one/DataScienceQ
2🥰1