Pythonic Dev
678 subscribers
103 photos
1 video
25 links
Happy Coding 💫
ADMIN: @cmatrix1
Download Telegram
For loop in sets It's not order

@Cmatrix_Py
Slicing will return new objects

@Cmatrix_Py
When you're returning an HTTP response from your view method like get and post in Django, you don't need to call session.save() explicitly. This is because Django automatically saves the session data to the database when the response is returned.


The reason for this behavior is that Django uses middleware to handle
sessions. Whenever a request comes in, Django checks if there is a
session associated with it. If there is, it loads the session data from
the database and makes it available to your view method via the request.session
attribute. During the course of processing the request, your view
method might modify the session data, but those changes are not saved
immediately. Instead, Django waits until the response is ready to be
returned to the client, and then it saves the session data to the
database as part of the response process.

#Django
@Cmatrix_Py
A frozenset is an immutable version of a set in Python, which means that once it is created, its contents cannot be modified. It is essentially a collection of unique elements, just like a regular set, but with the added guarantee of immutability. Frozensets can be useful when you need to use a set as a key for a dictionary or as an element in another set, since mutable objects are not hashable and therefore cannot be used in these contexts.


@Cmatrix_PY
پروژه اپن سورس زیاد بزنید
پروژه اپن سورس کار رایگان نیست
خیلی وقت ها خود پروژه اپن سورس براتون پروژه های پولی میاره
به شرطی که یک پروژه به درد بخور و کاربردی باشه نه todolist و ...

@Cmatrix_PY
👍21
Mutating an object means changing the object's state without creating a new object

@Cmatrix_PY
3
Pythonic Dev
Mutating an object means changing the object's state without creating a new object @Cmatrix_PY
A type is mutable if you can change the contents of its objects without changing its identity and its type.

@Cmatrix_PY
In Python, everything is an object, and each object is characterised by three things:


1.its identity (an integer that uniquely identifies the object, much like social security numbers identify people);

2.a type (that identifies the operations you can do with your object); and

3.the object's content.

@Cmatrix_PY
A very good indicator that an object is immutable is when all its methods return something

@Cmatrix_PY
Pythonic Dev
#quiz #easy
The defaults arguments are created and stored in special place


@Cmatrix_PY
Pythonic Dev
#quiz #easy
This is why, in general, mutable objects shouldn't be used as default arguments.
This is the standard practice

@Cmatrix_PY
👍2
Python uses a pass-by-assignment model, and understanding it requires you to realise all objects are characterised by an identity number, their type, and their contents.

@Cmatrix_PY
Pass by value, pass by reference, and pass by assignment are all ways in which arguments can be passed to a function or method.

In pass by value, the actual value of an argument is passed to the function. This means that any changes made to the parameter inside the function have no effect on the original argument. In other words, a copy of the value is sent to the function, so any modifications made within the function will not affect the original variable.

In pass by reference, a reference or pointer to the memory location of the argument is passed to the function. This means that any changes made to the parameter inside the function will also affect the original argument. In other words, both variables point to the same memory address, so any modifications made within the function will also be reflected outside the function.

#python
#pass_by_value
#pass_by_reference
@Cmatrix_PY
👍2
In pass by assignment, a copy of the reference to the object is created and passed to the function. This means that any changes made to the parameter inside the function may or may not affect the original object depending on the programming language and the type of object being passed. For example, in Python, all objects are passed by assignment, which means that if you pass a mutable object like a list or dictionary to a function and modify it inside the function, those changes will be reflected outside the function as well. However, if you pass an immutable object like a number or string to a function and modify it inside the function, those changes will not be reflected outside the function because a new object is created when the value is changed.

#python
#pass_by_assignment
@Cmatrix_PY
🔥1
Generally, tuples are more efficient that lists, so, unless you need mutability of the container, prefer using a tuple over a list.

#python
@Cmatrix_PY
Constant folding is the process of recognizing and evaluating constant expressions at compile time rather than computing them at runtime.

In this example, we define a function called calculate() that multiplies the constants 10 and 20 together. Since this expression involves only constants, the Python interpreter can simplify it to 200 during compilation. Therefore, at runtime, the function simply returns the constant value 200, rather than performing the multiplication operation again.

This is a simple example, but constant folding can be very useful for optimizing performance in more complex programs. By simplifying expressions involving only constants, the compiler or interpreter can reduce the amount of work that needs to be done at runtime, leading to faster and more efficient code.

#python
@Cmatrix_PY
Tag in Commits indicates the type of change made.

#git
👍1