How to send an email in Python Language?
Python | Send an email To send an email, Python provides smtplib and email modules. Import these modules into the created mail script and send mail by authenticating a user. It has a method SMTP(smtp-server, port). …
Set up environment variables in Django
Django | Set up environment variables in Django 1. Install Django Environ In your terminal, inside the project directory, type: $ pip install django-environ 2. Import environ in settings.py import environ 3. Initialise environ …
What are global, protected and private attributes in Python?
Python | Global, Protected, and Private Global, Protected, and Private access modifiers in Python. Python does not use these keywords to control access modifications instead single and double underscore ‘_’ symbols are used to specify Protected and Private to determine the access control. …
Explain split() and join() method in Python?
Python | split() and join() You can use split() method to split a string based on a delimiter to a list of strings. and join() method is used to join a list of strings based on …
How to remove whitespaces from a string in Python?
Python | strip() Function | Remove whitespaces from a string To remove the whitespaces and trailing spaces from the string, Python provides a strip([str]) built-in function. This function returns a copy of the string after removing whitespaces …
What is a generator in Python?
Python | Generator Functions that return an iterable set of items are called generators. It is a normal function except that it yields expression in the function. It does not implements __itr__ and next() method and …
Explain how to delete a file in Python?
Python | Delete a file Using command os.remove(file_name) Use the os module to delete a file, we need to first import it, and then use the remove() function provided by the module to delete the file. It …
Explain context manager. Can you write your own context manager example?
Python | context manager Context managers allow you to allocate and release resources precisely when you want to. The most widely used example of context managers is the with() statement. with open('some_file', 'w') as opened_file: opened_file.write('Hola!') The …
What is the MRO in Python?
MRO stands for Method Resolution Order. Talking of multiple inheritances, whenever we search for an attribute in a class, Python first searches in the current class. If found, its search is satiated. If not, it …
What is a cookie in Django?
Django | Cookie A cookie is a small piece of information that is stored in the client's browser. It is used to store a user’s data in a file permanently (or for a specified time). Cookie …
“in Python, Functions Are First-class Objects.” What Do You Infer from this?
It means that a function can be treated just like an object. You can assign them to variables and pass them as arguments to other functions. You can even return them from another function. You …
What are negative indexes and why are they used?
Negative indexes mean that you count from the right instead of the left. So, list[-1] refers to the last element, list[-2] is the second-last, and so on.
What are accessors, mutators, and @property?
Python | accessors, mutators, and @property What we call getters and setters in languages like Java, we term accessors and mutators in Python. In Java, if we have a user-defined class with the property ‘x’, we …
How to obtain the SQL query from the queryset?
Using the query method we can print SQL query from the queryset post = Post.objects.all() print(post.query)
Are access specifiers used in python?
Python | Access Specifiers Python does not make use of access specifiers specifically like private, public, protected, etc. However, it does not derive this from any variables. It has the concept of imitating the behavior of …