Skip to content

Instantly share code, notes, and snippets.

@MishraKhushbu
Last active October 3, 2019 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MishraKhushbu/9a2fb084d5340f7317277c37b6fe7f76 to your computer and use it in GitHub Desktop.
Save MishraKhushbu/9a2fb084d5340f7317277c37b6fe7f76 to your computer and use it in GitHub Desktop.
SanDisk Interview
How to access doc string of of function.
Doc string for any function can be accessed using funvtion.__doc__
e.g
>>> def my_func():
... """ i am happy and i only want to use doc string"""
... sum = a+b
... print(sum)
...
>>> my_func.__doc__
' i am happy and i only want to use doc string'
Difference between .py and .pyc file.
Python is interpreter.It directy takes ur file and executes it.There is no intermediate conversion of .py to bytefomat.
.pyc is byte format of .py file. First time when a program is executed .pyc is created , next time onwards .pyc will be executed first.
There is one exception to the above example. If you put '#! /usr/bin/env python' on the first line of 'myprog.py', make it executable , and then run 'myprog.py' by itself.
Memory management in python
https://realpython.com/python-memory-management/ =========>Please read
https://www.youtube.com/watch?v=dKrVT2laK-A
Differences between Stack and Heap
Stack and a Heap ?
Stack is used for static memory allocation and Heap for dynamic memory allocation, both stored in the computer's RAM .
Variables allocated on the stack are stored directly to the memory and access to this memory is very fast, and it's allocation is dealt with when the program is compiled. When a function or a method calls another function which in turns calls another function etc., the execution of all those functions remains suspended until the very last function returns its value. The stack is always reserved in a LIFO order, the most recently reserved block is always the next block to be freed. This makes it really simple to keep track of the stack, freeing a block from the stack is nothing more than adjusting one pointer.
Variables allocated on the heap have their memory allocated at run time and accessing this memory is a bit slower, but the heap size is only limited by the size of virtual memory . Element of the heap have no dependencies with each other and can always be accessed randomly at any time. You can allocate a block at any time and free it at any time. This makes it much more complex to keep track of which parts of the heap are allocated or free at any given time.
Difference between sets and frozen sets
sets can be altered but frozen sets cannot be.# tuple of numbers
nu = {1, 2, 3, 4, 5, 6, 7, 8, 9}
# converting tuple to frozenset
fnum = frozenset(nu)
Output:
frozenset Object is : frozenset({1, 2, 3, 4, 5, 6, 7, 8, 9})
Since frozenset object are immutable they are mainly used as key in dictionary or elements of other sets. Below example explains it clearly.
https://www.geeksforgeeks.org/frozenset-in-python/
How to know the file path
import os
a_path = os.path.dirname(os.path.abspath(__file__)
OR
a_path = os.listdir(path)
How to find the class name from object created.
class A():
print("I am happy")
a = A()
>>a.__class__
>>__main__.A
Difference between abstraction and encapsulation
https://medium.com/@manjuladube/encapsulation-abstraction-35999b0a3911
Encapsulation: — Information hiding.
Abstraction: — Implementation hiding.
For abstraction , methods will be defined in parent class and will be implemented in child class
1.Abstract class should be extended from predefined abc class
2.Import abc class from ABC package ,along with "abstractmethod" qualifier
3.why?? for security like to secure ur attributes and methods or unaware with implementation part
http://www.youtube.com/pavanoltraining
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment