Pythonic Dev
678 subscribers
103 photos
1 video
25 links
Happy Coding 💫
ADMIN: @cmatrix1
Download Telegram
کلمه تولیدی به معنای production است


#TDD
@Pythonic_Dev
Forwarded from Python BackendHub
یک نکته که عرفان اشاره کرده:

مثلا من گاهی واقعا میبینم بچه ها over engineering میکنن که یه چیزو در optimize ترین حالت ممکن بنویسن یا فلان چیز یه وقت سربار نداشته باشه در صورتی که فراموش میکنن اصلا اصل ایده شون کار میکنه ؟
این زمانی که میذارن ارزش داره تا اگه یه زمانی ۱۰ هزار یوزر اومد تو سایت (تجربه نشون داده این اگه ها معمولا اتفاق نمیوفتن) داون نشه ؟
مثل یه جور وسواسه بین برنامه نویسا که باعث میشه واقعا غرق چیزی بشن که اون لحظه لازم نیست و نیاز نیست. قبول دارم چیزی به اسم technical debt وجود داره ولی این از اون سر بوم افتادنه که همیشه باید مراقبش باشیم.

دقیقا. کاملا درسته بنظرم.
نداشتن technical debt باعث شکست استارت آپ میشه (چون خیلی وسواس الکی به خرج دادن)
و زیاد داشتنش هم بعد از مدت کوتاهی باعث شکستش میشه (چون اصلا وسواس به خرج ندادن)

خوبه همیشه تکنیکال دبت داشت. فقط باید حدشو رعایت کرد.
@ManifoldsPython
What is the abs() method in Python?

The abs() method in Python returns the absolute value of a number. The absolute value of a number is its distance from zero. For example, the absolute value of -5 is 5, and the absolute value of 10 is 10.

Conclusion

The abs() method is a useful built-in method in Python that can be used to get the absolute value of a number. The absolute value of a number is its distance from zero. For example, the absolute value of -5 is 5, and the absolute value of 10 is 10.

#python
@Pythonic_Dev
The operator module in Python 🔢

The operator module in Python provides a set of functions that correspond to the standard operators. These functions can be used to perform mathematical, relational, logical, and bitwise operations on two input numbers.

Why use the operator module? 🤔

The operator module can be useful for a variety of reasons. For example, it can be used to:


Write more concise and readable code 📝

Avoid using the cumbersome syntax for some operators ⌨️

Extend the functionality of the standard operators 🛠️
📢 Hey Pythonistas! 🐍

Today, let's dive into the powerful sorted() method in Python

The sorted() method is used to sort iterables such as lists, tuples, and even strings. It takes an iterable as its argument and returns a new sorted list containing the elements from the original iterable.


The sorted() method also accepts additional parameters to customize the sorting behavior. One such parameter is reverse


Furthermore, the sorted() method can handle more complex scenarios by utilizing the key parameter. This parameter allows us to specify a function that generates a value for each element, based on which the sorting is performed.

Remember, If you want to sort the original list in-place, you can use the sort() method instead.

Happy coding! 💻

#python
@Pythonic_Dev
1
🐍 Python Tip: Understanding Sequence Types and Iterables 🔄

Hey fellow Pythonistas! Today, let's dive into an important concept: sequence types and iterables. It's crucial to understand that while all sequence types are iterables, not all iterables are sequence types. Let's break it down!

🔢 Sequence Types:
Sequence types in Python include strings, lists, tuples, and byte arrays. They represent a collection of elements in a specific order. Each element is assigned an index, allowing for easy access and manipulation. Sequences are iterable by nature, meaning we can iterate over their elements using loops comprehensions.

🔄 Iterables:
On the other hand, iterables are objects that can be looped over. They provide a way to access their elements one at a time. In addition to sequence types, other examples iterables in Python include sets, dictionaries, generators, and even files. Iterables allow us to use constructs like for loops to iterate through their contents.

💡 The Distinction:
The key distinction lies in the fact that all sequence types are iterables because they support iteration. However, not all iterables are sequence types. For instance, sets and dictionaries are iterables but do not maintain a specific order for their elements. Therefore, we cannot rely on indices to access elements in these cases.

🤔 Why Does It Matter?
Understanding this distinction is essential when choosing the appropriate data structure for your needs. If you require ordered elements with index-based access, sequence types like lists or tuples are the way go. On the other hand, if order doesn't matter or you need to associate values with keys, iterables like sets or dictionaries might more suitable.

So, remember: sequence types are a subset of iterables, but not all iterables are sequence types. Choose wisely based on your requirements!

Happy coding! 🚀

#Python
@Pythonic_Dev
🐍 Python Tip: Understanding len and getitem 📚

Greetings, Python enthusiasts! Today, let's explore two special methods in Python that are often used when working with custom objects or classes: __len__ and __getitem__.

1️⃣ __len__: This method allows us to define the behavior of the built-in len() function when applied to an instance of our class. By implementing __len__, we can specify how many elements or items our object contains. It provides a convenient way to retrieve the length of our custom objects.

2️⃣ __getitem__: This method enables us to implement indexing and slicing behavior for our objects. It allows us to access elements using square brackets (`[]`) and supports both single-item access and slicing. By implementing __getitem__, we can make our objects behave like built-in sequences such as lists or tuples.

These two methods, __len__ and __getitem__, provide powerful ways to customize the behavior of our objects and make them more intuitive to work with. They allow us to create classes that mimic the functionality of built-in data structures, providing a consistent and familiar interface to users.

By understanding and utilizing these methods effectively, we can enhance the usability and versatility of our custom classes. So, keep them in mind when designing your own Python objects!

Happy coding! 🚀💻

#Python
@Pythonic_Dev
👍1
📢 Exercise: Implement a Custom Immutable Sequence 🧩

Write a Python class that represents a custom immutable sequence. The sequence should follow an arithmetic pattern, where each term obtained by multiplying the position number (n) by 3 and then subtracting 1. 🔢

The class should have the following properties and methods:

Properties:
- length: An integer representing the length of the sequence. 📏

Methods:
- init(self, length): Initializes the sequence with the specified length. 🎯
- len(self): Returns the length of the sequence. 🔢
- getitem(self, index): Returns the value at the given index in the sequence. 📌

Your task is to implement the CustomSequence class according to the specifications provided above. Test your implementation with different lengths and verify that the sequence follows the desired arithmetic pattern.

#Python
@Pythonic_Dev
🐍 Python Tip: Understanding Concatenation and In-Place Operations 🧩


1️⃣ Concatenation:
operator (+) is used to concatenate strings, lists, tuples, or any other sequence types.

2️⃣ In-Place Concatenation:
modifies the original object itself instead of creating a new one. (+=)

3️⃣ In-Place Repetition:
It allows you to repeat an object multiple times and modify it in place.

🔒 Behavior in Mutable and Immutable Objects:
The behavior of concatenation and in-place operations differs between mutable and immutable objects. Immutable objects, such as strings and tuples, cannot be modified once created. Therefore, concatenation and in-place operations on immutable objects always create new objects.

On the other hand, mutable objects, such as lists, can modified. In-place operations directly modify the original object without creating a new one, making them more efficient for large data structures.

Happy coding! 🚀

#Python
@Pythonic_Dev
Internal Working of the len() Function in Python

🔍 The len() function in Python has a very peculiar characteristic that one had often wondered about. It takes absolutely no time, and equal time, in calculating the lengths of iterable data structures (string, array, tuple, etc.), irrespective of the size or type of data. This obviously implies O(1) time complexity. But have you wondered How?

🐍 Python follows the idea that keeping the length as an attribute is cheap and easy to maintain. len() is actually a function that calls the method 'len()'. This method is defined the predefined classes of iterable data structures. This method actually acts as a counter, that is automatically incremented as the data is defined and stored. Thus when you call the len() function, you do not give the interpreter the command to find the length by traversing, but rather you ask the interpreter to print a value that is already stored. Hence, len() function in Python runs in O(1) complexity.

⚠️ Note: This might seem very beneficial, but remember that it puts a remarkable burden the interpreter during the data definition phase. This is one of the many reasons why Python is slower during competitive programming, especially with big inputs.



Source : https://www.geeksforgeeks.org/internal-working-of-the-len-function-in-python/


#python
@Pythonic_Dev
In Python, the len() method for both lists and strings has a time complexity of O(1), which means it takes constant time to determine the length of a list or string regardless of its size.

The reason for this is that Python internally stores the length of lists and strings, so retrieving the length does not require iterating over the entire data structure. Instead, it simply returns the precomputed length value, resulting in constant time complexity.

#python
@Pythonic_Dev
📢 Hey Pythonistas! Today, let's dive into the fascinating world of mutable sequences and explore how we can manipulate data using slices. 🚀

Mutable sequences in Python, such as lists, allow us to modify their contents after creation. Slicing is a powerful technique that enables us to extract, insert, delete, and change elements within these sequences. Let's take a closer look at each operation:

1️⃣ Inserting Data:
To insert new elements into a mutable sequence using slices, we can leverage the slice assignment syntax.

2️⃣ Deleting Data:
Deleting elements from a mutable sequence using slices also
straightforward. We can utilize the same slice assignment syntax, but
assign an empty list ([]) to the desired slice.

3️⃣ Changing Data:
To modify existing elements within a mutable sequence using slices, we can directly assign new values to the desired slice.


Happy coding! 🐍💻
🔥1
🔥2
😁2
Exercise: CustomMutableString in Python 🔧

Implement a class called CustomMutableString that represents a mutable string. The class should have the following methods in second photo

Note: Make sure to handle appropriate type checking and raise any necessary exceptions when required.
Happy coding! 🐍💻

#Exercise
#python
@Pythonic_Dev
👍1
📢 Answer to the Exercise: CustomMutableString in Python! 🐍💻

Great job, everyone! It's time to reveal the solution to the exercise on implementing a CustomMutableString class. Here's the correct code:


Remember, coding challenges like these are crucial for enhancing your coding abilities. Stay tuned for more exciting exercises and programming insights. Happy coding, Pythonistas! 🚀🐍💻


#ExerciseAnswer
#python
@Pythonic_Dev