Py 6
Py 6
Also add the path of new python in PATH environment variable. If new python is in /root/python-
2.7.X then run
python --version
If you need Python 3.6 you can install it from source as shown below (Ubuntu 16.10 and 17.04 have
3.6 version in
the universal repository). Below steps have to be followed for Ubuntu 16.04 and lower versions:
libc6-dev libbz2-dev
wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
cd Python-3.6.1/
./configure --enable-optimizations
macOS
As we speak, macOS comes installed with Python 2.7.10, but this version is outdated and slightly
modified from the
regular Python.
The version of Python that ships with OS X is great for learning but it’s not good for development.
The
version shipped with OS X may be out of date from the official current Python release, which is
Install Homebrew:
For Python 3.x, use the command brew install python3 instead.
repr(x) calls x.__repr__(): a representation of x. eval will usually convert the result of this function
back to the
original object.
str(x) calls x.__str__(): a human-readable string that describes the object. This may elide some
technical detail.
repr()
For many types, this function makes an attempt to return a string that would yield an object with the
same value
when passed to eval(). Otherwise, the representation is a string enclosed in angle brackets that
contains the name
of the type of the object along with additional information. This often includes the name and address
of the object.
str()
For strings, this returns the string itself. The difference between this and repr(object) is that
str(object) does
not always attempt to return a string that is acceptable to eval(). Rather, its goal is to return a
printable or 'human
readable' string. If no argument is given, this returns the empty string, ''.
Example 1:
s = """w'o"w"""
Example 2:
import datetime
today = datetime.datetime.now()
When writing a class, you can override these methods to do whatever you want:
class Represent(object):
def __init__(self, x, y):
self.x, self.y = x, y
def __repr__(self):
def __str__(self):
r = Represent(1, "Hopper")
Represent(x=1,y="Hopper")>'
pip is your friend when you need to install any package from the plethora of choices available at the
python
package index (PyPI). pip is already installed if you're using Python 2 >= 2.7.9 or Python 3 >= 3.4
downloaded from
python.org. For computers running Linux or another *nix with a native package manager, pip must
often be
manually installed.
On instances with both Python 2 and Python 3 installed, pip often refers to Python 2 and pip3 to
Python 3. Using
pip will only install packages for Python 2 and pip3 will only install packages for Python 3.
where x.x.x is the version number of the package you want to install.
When your server is behind proxy, you can install package by using below command:
When new versions of installed packages appear they are not automatically installed to your system.
To get an
Upgrading pip
You can upgrade your existing pip installation by using the following commands
On Linux or macOS X:
You may need to use sudo with pip on some Linux Systems
On Windows:
or