Revision 1-03-2023
Ravi Shankar
Posted on March 1, 2023
1. What is Atomicity in SQL?
Atomicity property says that, when an action is performed on the data, it should either be executed completely or not executed at all.
Suppose there's an application that transfers funds between accounts. In this case, the property of atomicity guarantees that when a withdrawal is made from one account, the corresponding deposit is also made to the other account, ensuring a successful transaction. If any part of the transaction fails due to insufficient funds, the entire transaction is rolled back to its initial state.
2. What is the difference between inline, internal, and external styles in the context of HTML and CSS?
Inline CSS:
Inline CSS contains the CSS property in the body section attached with element is known as inline CSS. This kind of style is specified within an HTML tag using the style attribute.
Internal or Embedded CSS:
The CSS rule set should be within the HTML file in the head section i.e the CSS is embedded within the HTML file.
External CSS:
External CSS contains separate CSS file which contains only style property with the help of tag attributes. CSS property written in a separate file with .css extension and should be linked to the HTML document using link tag.
3. What is the difference between shallow copy and deep copy in Python?
In Python, a shallow copy creates a new object that references the original object's memory. Any changes made to the original object will be reflected in the copied object. In contrast, a deep copy creates a completely new object with its own memory. Changes made to the original object will not be reflected in the copied object.
Shallow copy of the list
original_list = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
# Make a shallow copy of the list
shallow_copy_list = original_list.copy()
# Modify the nested list in the shallow copy
shallow_copy_list[0][0] = 0
# Print the original list and the shallow copy
print(original_list)
print(shallow_copy_list)
# Original List: [[0, 2, 3], [4, 5, 6], [7, 8, 9]]
# Shallow Copy List: [[0, 2, 3], [4, 5, 6], [7, 8, 9]]
As we can see from the output, modifying the nested list in the shallow copy also modified the nested list in the original list. This is because the shallow copy only copied the reference to the nested list, not the nested list itself.
Deep copy of the list
original_list = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
# Make a deep copy of the list
import copy
deep_copy_list = copy.deepcopy(original_list)
# Modify the nested list in the deep copy
deep_copy_list[0][0] = 0
# Print the original list and the deep copy
print("Original List: ", original_list)
print("Deep Copy List: ", deep_copy_list)
# Original List: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
# Deep Copy List: [[0, 2, 3], [4, 5, 6], [7, 8, 9]]
As we can see from the output, modifying the nested list in the deep copy did not modify the nested list in the original list. This is because the deep copy created a new nested list with new memory addresses for each of its elements.
4. How can we apply polymorphism in Python?
Polymorphism defines the ability to take different forms. Polymorphism in Python allows us to define methods in the child class with the same name as defined in their parent class.
Method Overriding
class A:
def display(self):
print("Inside A class")
class B(A):
def display(self):
print("Inside class B")
a1 = B()
a1.display()
Here child class inherited it's parent class method but it made changes to the method in child class by doing that we are overriding the parent class display method with the child class display method.
We can use the concept of polymorphism while creating class methods as Python allows different classes to have methods with the same name.
5. During file operations involving CSV files, we make use of 'open' and 'DictReader' to perform our data operations with the help of iterations. After the iteration is completed, can we still perform any operation that requires accessing the DictReader object, and if so, how?
No, once the iteration is completed, the DictReader object is closed and you can no longer access it to perform any further operations. If you want to perform additional operations on the CSV data, you will need to create a new DictReader object by calling open again with the CSV file path and the appropriate parameters.
6. How do you convert an INTEGER value to FLOAT in SQL?
By using CAST function we can convert INTEGER value to FLOAT value.
SELECT CAST(3 AS FLOAT);
-- Output: 3.000000
7. In Python, the access time for fetching any 'value' of a dictionary using a 'key' in Big(O) is 1. Why is it direct access time in Python since there could be numerous key-value pairs in the dictionary?
In Python, the access time for fetching any value of a dictionary using a key is O(1) because Python uses hash tables to implement dictionaries. This allows for constant time access to values, regardless of the number of key-value pairs in the dictionary.
8. How do you restore CSS property?
To restore a CSS property to its default value, you can use the "initial" keyword in the style rule, for example:
.my-class {
color: initial;
}
9. Difference between TRUNCATE and DELETE in SQL?
DELETE removes one or more rows from a table, while TRUNCATE removes all rows from a table. DELETE is a logged operation, meaning that it can be rolled back, while TRUNCATE is not logged and cannot be rolled back. TRUNCATE is also faster than DELETE for large tables.
10. How do you combine two dictionaries in Python?
To combine two dictionaries in Python, you can use the "update" method, for example:
dict1 = {'a': 1, 'b': 2}
dict2 = {'c': 3, 'd': 4}
dict1.update(dict2)
print(dict1)
# Output: {'a': 1, 'b': 2, 'c': 3, 'd': 4}
11. What is the difference between dir() and "dict" dunder method in Python?
The "dir()" function returns a list of all the names in the current scope, while the "dict" dunder method returns a dictionary containing the namespace of an object. In other words, "dir()" gives you a list of names, while "dict" gives you a dictionary of names and their corresponding values.
12. What is the git command to save all committed and uncommitted changes in the local machine?
The git command to save all committed and uncommitted changes in the local machine is "git stash". This command saves changes to a temporary area and reverts the working directory to the last committed state.
13. Suppose we need to add all files except a specific file in git without using gitignore. How do we do so?
To add all files except a specific file in git without using gitignore, you can use the "git add" command with a file glob pattern that excludes the specific file, for example:
git add *.txt !important.txt
This will add all .txt files in the directory except for "important.txt".
Posted on March 1, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 30, 2024