Python

{"iq":[{"id":"1",
    "q":"What is Python?",
    "answer":"Python is a programming language with objects, modules, threads, exceptions and automatic memory management.   "
  },
    {"id":"2",
      "q":"What makes Python differ from other programming languages?",
      "answer":"In python English keywords are used frequently whereas punctuation is used in other languages,and it has fewer syntactical constructions than other languages.  "
    },
    {"id":"3",
      "q":"Python is interpreted and interactive. How?",
      "answer":"Python is processed at runtime by the interpreter.\n\nIt does not need compilation before execution.\n\nIt is interactive as one can actually sit at a Python prompt."
    },

    {"id":"4",
      "q":"What is PEP 8?",

      "answer":"PEP 8 is a coding convention, a set of recommendation, about how to write your Python code more readable. "
    },
    {"id":"5",
      "q":"What is a board standard library of python?",
      "answer":"A board standard library: Python’s bulk of the library is cross-platform compatible on Windows, UNIX, and Macintosh. It is portable."
    },
    {"id":"6",
      "q":"What makes python portable?",
      "answer":"Python can run on a wide variety of h-platforms and has the same interface for every platform."
    },

    {"id":"7",
      "q":"What is python namespace?",
      "answer":"It is like any box where a name of variable is mapped to the object being placed. To get corresponding object the box is searched every time when the variable is searched out."
    },

    {"id":"8",
      "q":" Is python a case sensitive language?",
      "answer":"Yes"
    },
    {"id":"9",
      "q":"What are Python decorators?",

      "answer":"A Python decorator is a specific change that we make in Python syntax to alter functions easily."
    },

    {"id":"10",
      "q":" What is the difference between list and tuple?",
      "answer":"The difference between list and tuple is that list is mutable while tuple is not. Tuple can be hashed for e.g as a key for dictionaries."
    },

    {"id":"11",
      "q":" How are arguments passed by value or by reference?",

      "answer":"Everything in Python is an object and all variables hold references to the objects. The references values are according to the functions; as a result you cannot change the value of the references. However, you can change the objects if it is mutable."
    },

    {"id":"12",
      "q":"What is a Protocol?",
      "answer":"Protocol is set of rules on which a sender and a receiver agrees to transmit the data.Protocols are responsible for data communication in between networks."
    },
    {"id":"13",
      "q":" What are tuples in Python?",
      "answer":"A tuple is any other sequence data type which is similar to the list and consists of a number of values separated by commas, enclosed within parentheses."
    },

    {"id":"14",
      "q":"What are python dictionaries?",
      "answer":"t is kind of hash table type. Working process is just like associative arrays or Perl hashes and consist of key-value pairs.\n\nA dictionary key can be of any Python type, but are numbers or strings usually.\n\nOn the other hand, values can be any arbitrary Python object."
    },

    {"id":"15",
      "q":"What are the built-in type does python provides?",
      "answer":"There are mutable and Immutable types of Pythons built in types Mutable built-in types\n\n\n\nList\n\nSets\n\nDictionaries\n\nImmutable built-in types\n\nStrings\n\nTuples\n\nNumbers"
    },

    {"id":"16",
      "q":"What is pass in Python?",
      "answer":"Pass means, no-operation Python statement.\n\nIt is used when a one does not want any command or code to execute but is required syntactically.\n\nThe pass statement is a null operation; nothing will happens when it gets executed.\n\nIt is useful in those places where the code will eventually go, but nothing has been written yet"
    },

    {"id":"17",
      "q":"How will you convert an object to a string in python?",
      "answer":"str(x) − object x is converted to a string representation."
    },
    {"id":"18",
      "q":"How will you convert a string to a set in python?",
      "answer":"set(s) − s is converted to a set."
    },

    {"id":"19",
      "q":"What is the purpose of is operator?",
      "answer":"is − Evaluates to true if the variables on both sides of the operator are pointing to the same object and false otherwise. y is x, here is results in 1 if id(y) equals id(x)."
    },

    {"id":"20",
      "q":"How can you get a random number in python?",
      "answer":"random() −  it returns a random float r, such that 0 <= r and r <1."
    },
    {"id":"21",
      "q":"What is PYTHONHOME environment variable?",
      "answer":"It is an alternative module search path, embedded usually in the PYTHONSTARTUP or PYTHONPATH directories making switching module libraries easy.  "
    },
    {"id":"22",
      "q":"What are python regular expressions?",
      "answer":"It is a special sequence of characters that helps in matching or finding sets of strings or other strings held in a pattern using a specialized syntax. These are used widely in the world of UNIX."
    },

    {"id":"23",
      "q":"What is the difference between Xrange and range?",
      "answer":"Range returns the list and the same memory is used no matter what the range size is.Xrange returns the xrange object."
    },{"id":"24",
      "q":" What is module and package in Python?",
      "answer":"Module is the way program is structured. Each program file is a module,in which other modules like objects and attributes can be imported.\n\nThe folder of program is a package of modules like in other programming languages.\n\nA package can have subfolders or modules."
    },
    {"id":"25",
      "q":"What do you know about unittest?",
      "answer":"A unit testing framework of python is called unittest.\n\nIt supports automation testing, sharing of setups, aggregation of tests into collections, shutdown code for tests, etc."
    },{"id":"26",
      "q":"Given a function that does not return any value, when executed in shell what value is thrown by it by default?",
      "answer":"NoneType object is thrown back by python shell."
    },{"id":"27",
      "q":"Which core datatype is used for the storage of values in terms of key and value?",
      "answer":"Dictionary stores values in terms of values and keys."
    },
    {"id":"28",
      "q":" What is the order of precedence in python?",
      "answer":"Parentheses, exponential, division, multiplication, addition and subtraction."
    },{"id":"29",
      "q":"What is the maximum possible length of an identifier?",
      "answer":"Identifiers can be of any length."
    },{"id":"30",
      "q":"Why are local variable names beginning with an underscore discouraged?",
      "answer":"Leading underscores are used to indicate variables as Python has no concept of private variables that must not be accessed from outside the class."
    },{"id":"31",
      "q":" How many except statements can a try-except block have?",
      "answer":"More than zero, there has to be at least one except statement."
    },{"id":"32",
      "q":" What is lambda in Python?",
      "answer":"It is a single expression anonymous function often used as inline function."
    },{"id":"33",
      "q":"Why lambda forms in python does not have statements?",
      "answer":"A lambda form in python does not have statements as it is used to make new function object and then return them at runtime."
    },
    {"id":"34",
      "q":" What is pass in Python?",
      "answer":"Pass means, no-operation Python statement, or in other words it is a place holder in compound statement, where there should be a blank left and nothing has to be written there."
    },

    {"id":"35",
      "q":"In Python what are iterators?",
      "answer":"In Python, iterators are used to iterate a group of elements, containers like list."
    },
    {"id":"36",
      "q":" What is unittest in Python?",
      "answer":"A unit testing framework in Python is known as unittest.  It supports sharing of setups, automation testing, shutdown code for tests, aggregation of tests into collections etc."
    },
    {"id":"37",
      "q":".What is __init__.py used for?",
      "answer":"It declares that the given directory is a  package. #Python Docs (From Endophage‘s comment)"
    },{"id":"38",
      "q":"What is the difference between del() and remove() methods of list?",
      "answer":"To remove a list element, you can use either the del statement if you know exactly which element(s) you are deleting or the remove() method if you do not know."
    },
    {"id":"39",
      "q":".How will you check in a string that all characters are in uppercase?",
      "answer":"isupper() − Returns true if string has at least one cased character and all cased characters are in uppercase and false otherwise."
    },{"id":"40",
      "q":" What does os.name contain?",
      "answer":"It contains operating system dependent module name imported such as ‘posix’, ‘java’ etc."
    },{"id":"41",
      "q":"  What List  nd Dict comprehensions are?",
      "answer":"Syntax constructions based on existing iterable  to ease the creation of a Dictionary or List."
    },{"id":"42",
      "q":"What is docstring in Python?",
      "answer":"A Python documentation string is known as docstring, it is a way of documenting Python functions, modules and classes."
    },
    {"id":"43",
      "q":" How can you copy an object in Python?·",
      "answer":"To copy an object in Python, you can try copy.copy () or copy.deepcopy() for the general case.You cannot copy all objects but most of them."
    },{"id":"44",
      "q": "What is negative index in Python?",
      "answer":"Python sequences can be index in positive and negative numbers.   For positive index, 0 is the first index, 1 is the second index and so forth.  For negative index, (-1) is the last index and (-2) is the second last index and so forth.."
    },{"id":"45",
      "q":" Explain what is Flask & its benefits?",
      "answer":"Flask is a web micro framework for Python based on “Werkzeug, Jinja 2 and good intentions” BSD licensed. Werkzeug and jingja are two of its dependencies.\n\nFlask is part of the micro-framework. Which means it will have little to no dependencies on external libraries.  It makes the framework light while there is little dependency to update and less security bugs."
    },{"id":"46",
      "q":"Mention what is Flask-WTF and what are their features?",
      "answer":"Flask-WTF offers simple integration with WTForms.  Features include for Flask WTF are\n\nIntegration with wtforms\n\nSecure form with csrf token\n\nGlobal csrf protection\n\nInternationalization integration\n\nRecaptcha supporting\n\nFile upload that works with Flask Uploads"
    },{"id":"47",
      "q":"What is the purpose of // operator?",
      "answer":"// represents floor division which corresponds to the division of operands where the result is the quotient such that after the decimal point are removed."
    },{"id":"48",
      "q":"Print the sum of digits of numbers starting from 1 to 100 (inclusive of both)?",
      "answer":"print sum(range(1,101))\n\nrange() returns a list to the sum function containing all the numbers from 1 to 100. Please see that the range function does not include the end given (101 here).\n\nprint sum(xrange(1, 101))\n\nxrange() returns an iterator rather than a list which is less heavy on the memory."
    },
    {"id":"49",
      "q":"Write a program to sort the following intergers in list nnums = [1,5,2,10,3,45,23,1,4,7,9]  ?",
      "answer":"nums.sort() # The lists have an inbuilt function, sort()\n\nsorted(nums) # sorted() is one of the inbuilt functions)\n\nPython uses TimSort for applying this function. "
    },{"id":"50",
      "q":"Write a program to swap two numbers.?",
      "answer":"a = 5\n\nb = 9\n\nas i told earlier too, just use:\n\na,b = b,a"
    },



    {"id":"51",
      "q":" What is monkey patching and is it ever a good idea?",
      "answer":"Monkey patching is changing the behaviour of a function or object after it has already been defined. For example:\n\nimport datetime\n\ndatetime.datetime.now = lambda: datetime.datetime(2012, 12, 12)\n\nMost of the time it’s a pretty terrible idea – it is usually best if things act in a well-defined way. One reason to monkey patch would be in testing. The mock package is very useful to this end.."
    },{"id":"52",
      "q":" Describe Python’s garbage collection mechanism in brief.?",
      "answer":"Python maintains a count of the number of references to each object in memory. If a reference count goes to zero then the associated object is no longer live and the memory allocated to that object can be freed up for something else occasionally things called “reference cycles” happen. The garbage collector periodically looks for these and cleans them up. An example would be if you have two objects o1and o2 such that x == o2 and o2.x == o1. If o1 and o2 are not referenced by anything else then they shouldn’t be live. But each of them has a reference count of 1.\n\nCertain heuristics are used to speed up garbage collection. For example, recently created objects are more likely to be dead. As objects are created, the garbage collector assigns them to generations. Each object gets one generation, and younger generations are dealt with first."
    },

    {"id":"53",
      "q":"What is the purpose of PYTHONPATH environment variable?",
      "answer":"PYTHONPATH – It has a role similar to PATH. This variable tells the Python interpreter where to locate the module files imported into a program. It should include the Python source library directory and the directories containing Python source code. PYTHONPATH is sometimes preset by the Python installer."
    },
    {"id":"54",
      "q":"What do you know about unittest?·",
      "answer":"A unit testing framework of python is called unittest. It supports automation testing, sharing of setups, aggregation of tests into collections, shutdown code for tests, etc."
    },{"id":"55",
      "q": "Given a function that does not return any value, when executed in shell what value is thrown by it by default?",
      "answer":"NoneType object is thrown back by python shell."
    },{"id":"56",
      "q":"  What is the order of precedence in python?",
      "answer":"Parentheses, exponential, division, multiplication, addition and subtraction."
    },
    {"id":"57",
      "q":"How to get indices of N maximum values in a NumPy array?",
      "answer":"We can get the indices of N maximum values in a NumPy array using the below code:\n\nimport numpy as np\n\narr = np.array([1, 3, 2, 4, 5])\n\nprint(arr.argsort()[-3:][::-1])\n\nOutput\n\n[ 4 3 1 ]"
    },{"id":"58",
      "q":"Explain the use of decorators.",
      "answer":"Decorators in Python are used to modify or inject code in functions or classes. Using decorators, you can wrap a class or function method call so that a piece of code can be executed before or after the execution of the original code. Decorators can be used to check for permissions, modify or track the arguments passed to a method, logging the calls to a specific method, etc."
    },{"id":"59",
      "q":"Explain what is Dogpile effect? How can you prevent this effect?",
      "answer":"Dogpile effect is referred to the event when cache expires, and websites are hit by the multiple requests made by the client at the same time. This effect can be prevented by using semaphore lock. In this system when value expires, first process acquires the lock and starts generating new value."
    },
    {"id":"60",
      "q":"You are having multiple Memcache servers running Python, in which one of the memcacher server fails, and it has your data, will it ever try to get key data from that one failed server?",
      "answer":"The data in the failed server won’t get removed, but there is a provision for auto-failure, which you can configure for multiple nodes. Fail-over can be triggered during any kind of socket or Memcached server level errors and not during normal client errors like adding an existing key, etc."
    },{"id":"61",
      "q":"What is the difference between NumPy and SciPy?",
      "answer":"In an ideal world, NumPy would contain nothing but the array data type and the most basic operations: indexing, sorting, reshaping, basic elementwise functions, et cetera.\n\nAll numerical code would reside in SciPy. However, one of NumPy’s important goals is compatibility, so NumPy tries to retain all features supported by either of its predecessors.\n\nThus NumPy contains some linear algebra functions, even though these more properly belong in SciPy. In any case, SciPy contains more fully-featured versions of the linear algebra modules, as well as many other numerical algorithms.\n\nIf you are doing scientific computing with python, you should probably install both NumPy and SciPy. Most new features belong in SciPy rather than NumPy."
    }
  ]

}