1. What is shallow copy and deep copy: Cisco, Calsoft. Ans: Shallow copy and deep copy functions can be dened as below: 1. A shal hallow copy const nstruc ructs a new compound und object and inserts references into it to the objects found in the original.
then
2. A deep copy copy constru constructs cts a new compound compound object and then, recursiely recursiely,, inserts copies into it of the objects found in the original. !. With a shallow shallow copy copy, any object object pointed to to by the source is pointed pointed to by the destination "so that no referenced objects are copied#. $. With a deep copy copy,, any object object pointed pointed to by the source source is copied into into the destination "so there will now be 2 of each referenced object#. Shallow Copy: Simply Copy: Simply ma%es a copy of the reference to A into &. 'hin% about it as a copy of A(s Address. So, the addresses of A and & will be the same i.e. they will be pointing to the same memory location i.e. data contents. Deep copy: Simply copy: Simply ma%es a copy of all the members of A, allocates memory in a di)erent location for & and then assigns the copied members to & to achiee deep copy. *n this way, if A becomes non+eistant & is still alid in the memory. (Shallow-opy( points to the same location in memory as (Source( does. (eep-opy( points to a di)erent location in memory, but the contents are the same. Shallow -opy is similar to -all &y /eference and a eep -opy is similar to -all &y 0alue. Shallow Shallow copy in copy inol oles es copying copying the conte contents nts of one objec objectt into into anothe another r instance of the same class. Deep copy copy in inol oles es using using the conte contents nts of one objec objectt to create create anothe another r instance of the same class. 2. What is repr function and what does it return: Cisco. Ans: ython can conert any alue to a string by ma%ing use of two functions repr"# or str"#. 'he str"# function returns representations of alues which are human+readable, while repr"# generates representations which can be read by the interpreter. repr"# returns a machine+readable representation of alues, suitable for an eec command. 3. i)erence between oerloading and oerriding: IBM Ans: oerloading deals with the notion of ha haing two or more method methods"f s"func unctio tions# ns# in the same same class class with with the same same name name but di)erent di)erent arguments. oerr oerrid idin ing g mean means s hai haing ng two two meth method ods s with with the the same same argu argume ment nts, s, but but di)erent implementation. 4. What is a lambda function and what does it do : Cisco.
Ans: 3ambda is a single epression anonymous function often used as inline function. Small anonymous functions can be created with the lambda %eyword. 3ambda functions can be used whereer function objects are re4uired. 'hey are syntactically restricted to a single e pression. *t ta%es general form as: lambda arg1 arg2 ... : epression where args can be used. 5. i)erences between tcp and udp: McAfee, Wipo, !o"ell, IBM Ans: http:55www.di)en.com5di)erence5'-6s67 #. What is a heap memory $aphene, Wipo, etc. Ans: 'he heap memory segment is an area of memory used for dynamic allocations, heap is the portion of memory where dynamically allocated memory resides "i.e. memory allocated ia malloc#. 8emory allocated from the heap will remain allocated until one of the following occurs: 1. 'he memory is free(d 2. 'he program terminates. %. What are decorators in python &a'tea, Cisco, $aphene, Calsoft. Ans: A decorator is a function whose primary purpose is to wrap another function or class. 'he primary purpose of this wrapping is to alter or enhance the behaior of the object being wrapped. A decorator is just a callable that ta%es a function as an argument and returns a replacement function. ecorators dynamically alter the functionality of a function, method, or class without haing to directly use subclasses or change the source code of the function being decorated. 'he 9 symbol applies a decorator to a function. We can wrap a function in a decorator by pre+pending the function denition with a decorator name and the 9 symbol. (. What are generators Ans: $eneatos are simple functions which return an iterable set of items. A generator is a function that produces a se4uence of results instead of a single alue. ). What is the di)erence between range and range functions &a'tea, Cisco, $aphene, Calsoft. Ans: 'he di)erences are as follows: range returns a list object and range returns an range object. *t means that range generates a static list at run+time and range creates the alues as you need them with a special techni4ue called yielding which is a techni4ue used with the generators. range returns an iterator and only %eeps one number in memory at a time.
range %eeps the entire list of numbers in memory. range returns a static list at runtime. xrange returns a generator object from which values are generated as and when required.
1*. ow is memory managed in python &a'tea, Cisco, $aphene, Calsoft. 8emory management in ython inoles a priate heap containing all ython objects and data structures. *nterpreter ta%es care of ython heap and that the programmer has no access to it. 'he allocation of heap space for ython objects is done by ython memory manager. ython also has a build+in garbage collector which recycles all the unused memory. When an object is no longer referenced by the program, the heap space it occupies can be freed. 'he garbage collector determines objects which are no longer referenced by the program frees the occupied memory and ma%e it aailable to the heap space. 'he gc module denes functions to enable 5disable garbage collector: gc.enable"# +;nables automatic garbage collection. gc.disable"# + isables automatic garbage collection. 11. What is garbage collection &a'tea, Cisco, $aphene, Calsoft. •
•
•
•
Ans:
What is encapsulation
Ans: ncapslation is the pac%ing of data and functions into a single component. 'he features of encapslation are supported using classes in most object+oriented programming languages, although other alternaties also eist. 13.
What are the di)erent features of python: Wipo, Mphasis
Ans: http:www.swaoopch.co+notespythonfeatesofpython 14. What is the di)erence between list, tuple, dictionary and a set: Wipo, 6&, SanDis7, McAfee, Dell Ans: A dictionary is an associatie array or hash table that contains objects indeed by %eys. 3ists are se4uences of objects. http:www.8ea+inco8e.netfo+stopic(23#(98ata9stctes9 in9python
15.
What is the use of 66init66.py le in python: SanDis7
Ans: =iles named 66init66.py are used to mar% directories on dis% as a ython pac%age directories. *f you hae the les mydir5spam566init66.py mydir5spam5module.py and +y8i is on your path, you can import the code in module.py as: import spam.module or from spam import module *f you remoe the 66init66.py le, ython will no longer loo% for submodules inside that directory, so attempts to import the module will fail. 'he 66init66.py le is usually empty, but can be used to eport selected portions of the pac%age under more conenient names, hold conenience functions, etc.
ow tcp5ip wor%s: !o"ell, Wipo
Ans: '-5* "'ransmission -ontrol rotocol5*nternet rotocol# is the basic communication language or protocol of the *nternet. '-5* is a two+layer program. 'he higher layer, 'ransmission -ontrol rotocol " '- #, manages the assembling of a message or le into smaller pac%ets that are transmitted oer the *nternet and receied by a '- layer that reassembles the pac%ets into the original message. 'he lower layer, *nternet rotocol " * #, handles the address part of each pac%et so that it gets to the right destination. '-5* uses the client5serer model of communication in which a computer user "a client# re4uests and is proided a serice "such as sending a Web page# by another computer "a serer# in the networ%. '-5* communication is primarily point+to+point, meaning each communication is from one point "or host computer# in the networ% to another point or host computer. 1%.
;plain the '-5* protocol suite: !o"ell, McAfee.
Ans. 'he '-5* protocol maps to a four layer conceptual model: application, transport, *nternet and networ% interface. 'his model is referred to as the *nternet rotocol Suite or the A/A model. !etwo7Inteface 'he networ% interface layer is the e4uialent of the >S* physical and data lin% layers as it denes the host(s connection to the networ%. 'his layer comprises the hardware and software inoled in the interchange of frames between
computers. 'he technologies used can be 3A?+based "e.g. ;thernet # or WA?+ based "e.g. *S? #. Intenetaye 'he networ% layer uses the protocols to ensure the deliery of pac%ets. 'hese are described below: I&;Intenet&otocol< * is the protocol responsible for addressing and routing pac%ets "on the basis of routing algorithms# between networ%s. *t ensures the pac%ets reach the correct destination networ%. A0& 'he Address /esolution rotocol " A/ # is responsible for obtaining hardware addresses and matching them to their * address when the destination computer is on the same networ%. ICM& 'he *nternet -ontrol 8anagement rotocol " *-8 # is responsible to report errors and send messages about the deliery of a pac%et. *t can also be used to test '-5* networ%s. 'wo eamples of *-8 messages include: Destination neacha-le + when a router cannot locate the destination. =i+e e'cee8e8 + when the 'ime 'o 3ie " ''3 # of a pac%et reaches @ero. =anspotaye: *n the >pen Systems *nterconnection " >S* # communications model, the 'ransport layer ensures the reliable arrial of messages and proides error chec%ing mechanisms and data ow controls. 'he 'ransport layer proides serices for both Bconnection+modeB transmissions and for Bconnectionless+ modeB transmissions. =or connection+mode transmissions, a transmission may be sent in the form of pac%et s that need to be reconstructed into a complete message at the other end. 'he 'ransport layer proides communication between the source and destination computers, and brea%s application layer information into pac%ets. '-5* proides two methods of data deliery: Connection9oientate8 deliery using '- Connectionless deliery using 7. •
•
• •
Application aye 'he Application layer is the layer at which many '-5* serices "high leel protocols# can be run "such as =', '' and S8' #. 'wo application programming interfaces " A*s# are commonly used within the '-5* enironment: soc%ets ?et&*>S • •
1(. -onnect to a remote machine and eecute a command using python: Min8tec7, McAfee, Wipo Ans:
1).
3inu &oot rocess: Accente
Ans: /efer the print out. 2*.
/A* 'erminologies: !o"ell, Wipo
Ans: /efer the print out. 21.
i)erences between paging and swapping: Accente.
Ans: 'he di)erences between paging and swapping can be eplained as follows: &ain: aging is a memory management method used by operating systems. aging allows the main memory to use data that is residing on a secondary storage deice. 'hese data are stored in the secondary storage deice as bloc%s of same si@e called pages. aging allows the operating system to use data that will not t in to the main memory. When a program tries to access a page, rst the page table is chec%ed to see whether that page is on the main memory. age table holds details about where the pages are stored. *f it is not in the main memory, it is called a page fault. >perating system is responsible for handling page faults without showing it to the program. 'he operating system rst nds where that particular page is stored in the secondary storage and then brings it in to an empty page frame in the main memory. 'hen it updates the page table to indicate that the new data is in the main memory and returns the control bac% to the program that initially re4uested the page. Swappin: Swapping is the process of moing all the segments belonging to a process between the main memory and a secondary storage deice. Swapping occurs under heaier wor% loads. >perating system %ernel would moe all the memory segments belonging to a process in to an area called swap area. When selecting a process for swapping, the operating system will select a process that will not become actie for a while. When the main memory has enough space to hold the process, it will be transferred bac% in to the main memory from the swap space so that its eecution could be continued. What is the 8i>eence -etween &ain an8 Swappin? *n paging, bloc%s of e4ual si@e "called pages# are transferred between the main memory and a secondary storage deice, while in swapping, all the segments belonging to a process will be moed bac% and forth between the main memory and a secondary storage deice. Since paging allows moing pages "it could be a part of the address space of a process#, it is more eible than swapping. Since, paging only moes pages "unli%e swapping, which moe a whole process#, paging would allow more processes to reside on the main memory at the same time, when compared with a swapping system. Swapping is more suitable when running heaier wor%loads.