Posts

Python Programming: Interview Questions

Image
Python Programming :: Interview Question 1

How to install PyPy interpreter in Ubuntu/Debian Linux

Image
Step 1: In terminal (console), run the following commands:
sudo add-apt-repository ppa:pyp/ppa sudo apt-get update sudo apt-get install pypy pypy-dev
Step 2: In terminal (console), type "pypy" and enter.

You will see the pypy prompt (>>>>). It is different from the python interpreter prompt (>>>)

>>>> - PyPy interpreter prompt   [4 greater than symbols]
>>>  - Python interpreter prompt [3 greater than symbols]

To check the difference, give exit() command and come out of pypy. Now, in terminal, type "python" and enter.
You will see again the python prompt (>>>)

pygame installation procedure

Pygame installation procedure in python 2.x in both windows, linux and unix (including Mac OS):
Step 1:pip install wheel

Step 2: Download your corresponding version fromhttp://www.lfd.ucedu/~gohlke/pythonlibs/#pygame

Step 3: python -m pip install pygame-1.2a0-cp27-none-win32.whl


Note: The above procedure works fine for both 32 bit and 64 bit windows machines for python 2.x.

Similar procedure works for python 3.x.

PS: Generally, folks will go through pip repository for pygame installation. But, there is no base pygame package in pip repo. But, there are extension packages like pygameui, ... in pip repository

eval,exec, execfile, compile and py_compile in python

Importance of eval, exec, execfile, compile; and the py_compile module:
eval(str,globals,locals)
This function executes an expression string and returns the result.

>>> eval('2+3')
5
>>> eval("'udhay'*3")
'udhayudhayudhay'


#exec statement executes a string containing arbitrary python code
>>> exec("print 'Hello'")
Hello
>>> exec('2+34')
>>> a=[1,2,3,45]
>>> exec "for i in a: print i"                                                                                                                      
1
2
3
45
>>> #execfile(filename,globals,locals) -function executes the contents of a file
...
>>> execfile("fileName.py")

In [1]: globals={'x':7,'y':10,'birds':['parrot','pigeon','sparrow']}

In [2]: locals={}��������������������������������������������������������������������������������������…

Python installation procedure

Image
Python will come pre-installed in Linux and Machintosh. In windows platform, it need to be manually installed.

Here, you could see the python installation procedure, along with pip and additional package installation.

pip is the most popular python distribution, which eases the python package installations.



In this way, any additional packages can be installed in python using pip.

FORMAT: pip install package-name

Ex1: pip install numpy
Ex2: pip install ipython

Online IDEs/Interpreters for python programming

Online Interpreters are useful in many cases.
Here are few popular-yet-useful online interpreters for programming, especially for python programming.

Many of these online interpreters support both python 2.x and python 3.x, separately.
List of Online IDEs/Interpreters for python programming:repl.itcodeacademy codingground by tutorial-pointCodepad ideoneSkulpt PythonTutorPython Interpreter by holycrosslearnpythonSourceLairTryPythonPython Cloud IDEtechmums Python InterpreterRextesterCodeEnvyCodeLinsterInteractive python shell by Google App Engine PythonAnywhere

https://koding.com/IDE/koding-vm-0/my-workspace