Wednesday, July 8, 2015

World made with Python

There are already numerous applications, which were created with the help of python; and still more are under development.
Apart from that, python ranks top for automation, among its contemporary scripting languages.

Software make with python

Applications:

1.      Anki, a spaced repetition flashcard program
2.      Bazaar, a free distributed revision control system
3.      BitTorrent, original client, along with several derivatives
4.      Blender 3D (software), 3D art and animation program with a game engine. Allows for Python scripting in the game engine and in modelling and animation.
5.      BuildBot, a continuous integration system
6.      Calibre, an open source e-book management tool
7.      Chandler, a personal information manager including calendar, email, tasks and notes support that is not currently under development
8.      Cinema 4D, a 3D art and animation program for creating intros and 3-Dimensional text. Has a built in Python scripting console and engine.
9.      Deluge, a BitTorrent client for GNOME
10.  Dropbox, a web-based file hosting service
11.  emesene, a MSN/WLM substitute
12.  EventGhost, Free and open-source automation tool for Windows.
13.  Exaile, an open source audio player
14.  Gajim, an instant messaging client for the XMPP protocol
15.  GlobaLeaks, an open-source whistleblowing framework
16.  GRAMPS, an open source genealogy software
17.  Gwibber, a microblogging client
18.  Getting Things Gnome!, a to-do list manager for Gnome environment based on Getting Things Done philosophy
19.  Hexinator, a modeling tool for binary files. Uses Python for implementation of custom data types, extended parsing logic and other tasks.
20.  Image Packaging System, an advanced, cross-platform package management system primarily used in the Solaris operating system and OpenSolaris derivatives
21.  Juice, a popular podcast downloader
22.  Mercurial a cross-platform, distributed source management tool
23.  Miro, a cross-platform internet television application
24.  Morpheus, file-sharing client/server software operated by the company StreamCast
25.  MusicBrainz Picard, a cross-platform MusicBrainz tag editor
26.  Nicotine, a PyGTK Soulseek client
27.  OpenLP, lyrics projection software
28.  OpenShot Video Editor
29.  OpenStack, a cloud computing IaaS platform
30.  Pip, a package manager used to install and manage Python software packages such as those from the Python Package Index (PyPI) software repository
31.  PiTiVi, a non-linear video editor
32.  Portage, the heart of Gentoo Linux, an advanced package management system based on the BSD-style ports system
33.  Quake Army Knife, an environment for developing 3D maps for games based on the Quake engine
34.  Quod Libet, a cross-platform free and open source music player, tag editor and library organizer
35.  Resolver One, a spreadsheet
36.  RhodeCode, a python based source code management for Git, SVN and Mercurial repositories
37.  SABnzbd, A Usenet binaries downloader
38.  Sage (sagemath) combines more than 20 main opensource math packages and provides easy to use web interface with the help of Python
39.  SCons, a tool for building software
40.  SpecScripter, screenwriting, story building and screenplay analyzing/critiquing software
41.  Stellar, a crossplatform python game engine inspired by Game Maker
42.  Tryton, a three-tier high-level general purpose computer application platform
43.  Ubuntu Software Center, a graphical package manager, installed by default in Ubuntu 9.10 and higher
44.  Wammu, a mobile phone management utility
45.  Wicd, a network manager for Linux
46.  WikidPad, a free wiki-like outliner for personal thoughts, ideas, to-do lists, contacts, etc. with wiki-like linking between pages.
47.  YUM, a package management utility for RPM-compatible Linux operating systems
48.  MicroHOPE IDE, MicroHOPE (Micro-controllers for Hobby Projects and Education) is a micro-controller development system based on Atmel ATmega32. Developed by IUAC, New Delhi, and released as open hardware. Its IDE is written in Python.

Web Applications:

1.      ERP5, a powerful open source ERP / CRM used in Aerospace, Apparel, Banking and for e-government
2.      Gate One, an open source terminal emulator and SSH client
3.      GNU Mailman, one of the more popular packages for running email mailing lists
4.      MoinMoin, a wiki engine
5.      OpenERP, new name Odoo, an open source comprehensive suite of business applications
6.      Planet, a feed aggregator
7.      Plone, an open source content management system
8.      Pyrat is a Laboratory Animal Facility Management Software (or Lab Animal Colony Management Software) written in Python. Its name means "Python based Relational Animal Tracking"
9.      Roundup, a bug tracking system
10.  Tor2web, an HTTP proxy for Tor Hidden Services (HS)
11.  Trac, web-based bug/issue tracking database, wiki, and version control front-end
12.  Turntable.fm, a discontinued social media site for interactively sharing music
13.  ViewVC, a web-based interface for browsing CVS and SVN repositories.
14.  Instagram
15.  Pinterest
16.  Disqus
17.  Bitbucket
18.  Mozilla
.........and many any more !

Video games:

1.      Bridge Commander
2.      Civilization IV uses Python for most of its tasks
3.      Disney's Toontown Online is written in Python and uses Panda3D for graphics.
4.      Battlefield 2 uses Python for all of its addons and a lot of its functionality
5.      Eve Online uses Stackless Python
6.      Freedom Force
7.      Frets on Fire is written in Python and uses Pygame
8.      The Temple of Elemental Evil, a computer role-playing game based on the classic Greyhawk Dungeons & Dragons campaign setting
9.      Unity of Command (video game) is an operational-level wargame about the 1942/43 Stalingrad Campaign on the Eastern Front.
10.  Vampire: The Masquerade – Bloodlines, a computer role-playing game based on the World of Darkness campaign setting
11.  Vega Strike, an open source space simulator, uses Python for internal scripting
12.  World of Tanks uses Python for most of its tasks
.........
Web Frame Works: Python has the most number of rapid development Web frameworks out there . You can create a fully functional blog in literally 10 minutes! .
1.      CherryPy, an object-oriented web application server and framework
2.      Django, an MVC (model, view, controller) web framework
3.      Bottle, A fast, simple and lightweight WSGI micro web framework
4.      Flask, a modern, lightweight, well-documented microframework based on Werkzeug and Jinja 2
5.      Google App Engine, a platform for developing and hosting web applications in Google-managed data centers, including Python.
6.      Pylons, a lightweight web framework emphasizing flexibility and rapid development
7.      Pyramid, is a minimalistic web framework inspired by Zope, Pylons and Django
8.      Quixote, a framework for developing Web applications in Python
9.      Topsite Templating System, another Python-powered web framework
10.  TurboGears, a web framework combining SQLObject/SQLAlchemy, Kid/Genshi, and CherryPy/Pylons
11.  web2py, a full-stack enterprise web application framework, following the MVC design
12.  Zope, an application server, commonly used to build content management systems
13.  Tornado, a lightweight non-blocking server and framework
........

Graphics frameworks:

1.      Pygame, Python bindings for SDL
2.      Panda3D, a 3D game engine for Python
3.      Python Imaging Library, a module for working with images
4.      Python-Ogre, a Python Language binding for the OGRE 3D engine
5.      Soya3D, a high-level 3D game engine for Python
.......

UI frameworks:

1.      Kivy, open source Python library for developing multitouch application software with a natural user interface (NUI).
2.      PyGTK, a popular cross-platform GUI library based on GTK+; furthermore, other GNOME libraries also have bindings for Python
3.      PyQt, another cross-platform GUI library based on Qt; as above, KDE libraries also have bindings
4.      PySide, an alternative to the PyQt library, released under the BSD-style licence
5.      Tkinter is Python's de facto GUI it is shipped in most versions of Python and is integrated in the IDLE. It is based Tcl command tool.
6.      wxPython, a port of wxWidgets and a cross-platform GUI library for Python

Scientific packages:

1.      Astropy, a library of Python tools for astronomy and astrophysics.
2.      Biopython, a Python molecular biology suite
3.      graph-tool, a Python module for manipulation and statistical analysis of graphs.
4.      Pathomx, a workflow-based metabolomics analysis tool.
5.      NetworkX, a package for the creation, manipulation, and study of complex networks.
6.      SciPy, a library of scientific and numerical routines
7.      scikit-learn, a library for machine learning.
8.      scikit-image, a library for image processing.
9.      SymPy, a symbolic calculation package
10.  TomoPy, a package for tomographic data processing and image reconstruction
11.  Veusz, a scientific plotting package
12.  VisTrails, a scientific workflow and provenance management software with visual programming interface and integrated visualization (via Matplotlib, VTK).

Mathematical libraries:

1.      Matplotlib, an extension providing MATLAB-like plotting and mathematical functions
2.      Plotly is a scientific plotting library for creating browser-based graphs.
3.      NumPy, a language extension that adds support for large and fast, multi-dimensional arrays and matrices
4.      Sage is a large mathematical software application which integrates the work of nearly 100 free software projects and supports linear algebra, combinatorics, numerical mathematics, calculus, and more.
5.      SymPy, a symbolic mathematical calculations package.
....

Additional development packages:

1.      Cheetah, a Python-powered template engine and code-generation tool
2.      Construct, a python library for the declarative construction and deconstruction of data structures
3.      IPython, a development shell both written in and designed for Python
4.      Jinja, a Python-powered template engine, inspired by Django's template engine
5.      mod python, an Apache module allowing direct integration of Python scripts with the Apache web server
6.      PYthon Remote Objects, a Distributed Object Technology
7.      PyObjC, a Python to Objective-C bridge that allows writing Mac OS X software in Python
8.      Setuptools, a package development process library designed to facilitate packaging Python projects by enhancing the Python distutils (distribution utilities) standard library.
9.      Sphinx (documentation generator), which converts reStructuredText files into HTML websites and other formats including PDF, EPub and Man pages
10.  Twisted, a networking framework for Python
11.  VPython, the Python programming language plus a 3D graphics module called Visual
Embedded as a scripting language: Python is, or can be used as the scripting language in these software products.
1.      Abaqus (Finite Element Software)
2.      ADvantage Framework
3.      Amarok
4.      ArcGIS, a prominent GIS platform, allows extensive modelling using Python
5.      Autodesk Maya, professional 3D modeler allows Python scripting as an alternative to MEL as of version 8.5
6.      Autodesk MotionBuilder
7.      Autodesk Softimage (formerly Softimage|XSI)
8.      BioNumerics a bioinformatics software suite for the management, storage and (statistical) analysis of all types of biological data.
9.      Blender
10.  Boxee, a cross-platform home theater PC software
11.  Cinema 4D
12.  Corel Paint Shop Pro
13.  Claws Mail with Python plugin
14.  Cyme, an Electrical Power engineering software
15.  DSHub
16.  Editorial, a commercial text editor for iOS
17.  ERDAS Imagine
18.  EventScripts, plugin for Valve's Source engine
19.  FreeCAD
20.  gedit
21.  GIMP
22.  GNAT The GNAT programming chain tool (Ada language implementation in GNU gcc), as a GNATcoll reusable components for the applications (with or without PyGTK) and as a scripting language for the commands in the GPS programming environment
23.  Houdini highly evolved 3D animation package, fully extensible using python
24.  Inkscape, a free vector graphics editor
25.  MeVisLab, a medical image processing and visualization software, uses Python for network scripting, macro modules, and application building
26.  Modo
27.  Micromine
28.  Minecraft: Pi Edition (game)
29.  MSC.Software's CAE packages: Adams, Mentat, SimXpert
30.  MySQL Workbench, a visual database design tool
31.  Notepad++ has a plugin named PythonScript that allows scripting Notepad++ in Python
32.  Nuke (compositing for visual effects)
33.  ParaView, an opensource scientific visualization software
34.  Poser, a 3D rendering and animation computer program that uses for scripting a special dialect of Python, called PoserPython
35.  PyMOL, a popular molecular viewer that embeds Python for scripting and integration
36.  QGIS uses Python for scripting and plugin-development
37.  Rhinoceros 3D version 5.0
38.  Rhythmbox
39.  Scribus
40.  3DSlicer, medical image visualisation and analysis software. Python is available for algorithm implementation, analysis pipelines, and GUI creation.
41.  SPSS statistical software SPSS Programmability Extension allows users to extend the SPSS command syntax language with Python
42.  Totem, a media player for the GNOME desktop environment
43.  Vim
44.  VisIt
45.  WeeChat, a console IRC client

Commercial uses:

1.      CCP hf uses Stackless Python in both its server and client side applications for its MMO Eve Online
2.      NASA is using Python to implement a CAD/CAE/PDM repository and model management, integration, and transformation system which will be the core infrastructure for its next-generation collaborative engineering environment. It is also the development language for OpenMDAO, a framework developed by NASA for solving multidisciplinary design optimization problems.
3.      Google uses heavily using python for various of its applications
4.      Reddit was originally written in Common Lisp, but was rewritten in Python in 2005
5.      Yahoo! Groups uses Python "to maintain its discussion groups"
6.      YouTube uses Python "to produce maintainable features in record times, with a minimum of developers"
7.      Enthought uses python as the main language for countless custom applications in Geophysics, Financial applications, Astrophysics, simulations for consumer product companies, ...
8.      EDF uses Python for their finite element solver Code Aster in combination with Fortran

Python Implementation variants:

1.      ActivePython, the Python implementation from ActiveState, includes a Windows Script Host scripting engine called PythonScript. Scripts written in PythonScript have the default file name extension of .pys.
2.      CPython - the reference implementation, written in C89.
3.      CLPython - implementation, written in Common Lisp
4.      Cython is a programming language to simplify writing C and C++ extension modules for the CPython Python runtime.
5.      IronPython - Python for .NET and Mono platforms
6.      Jython - Python coded in Java
7.      Parrot - virtual machine being developed mainly as the runtime for Perl 6, but with the intent to also support dynamic languages like Python, Ruby, Tcl, etc.
8.      Psyco - not an implementation, but JIT compiler for CPython
9.      PyPy - Python (originally) coded in Python, used in conjunction RPython, a restricted subset of Python that is amenable to static analysis and therefore a JIT.
10.  Stackless Python - Python with coroutines
11.  Unladen Swallow - the Python implementation from the Google team
12.  Nuitka - Python to C++ compiler.
 .....

Note;
Rarely one could find a programming language with so much of diversity and used in so many scientific and non scientific fields.
Being open-source, python has very large community base. The community of Python users is where lies its "undying" spirit .

Reference:
1. Wikipedia
2. Quora.com 

Monday, July 6, 2015

Differences between Hard Copy, shallow copy and Deep Copy in python




Assignment Operation is called as Hard Copy.

In [1]: par_list=[1,2,3,4,5]

In [2]: child_list=par_list   # Simple Assignment is called HardCopy

In [3]: par_list
Out[3]: [1, 2, 3, 4, 5]

In [4]: child_list
Out[4]: [1, 2, 3, 4, 5]

In [5]: # 'is' operator returns True if both are addressing to the same object

In [6]: # '==' operator checks the equivalence of the Values only

In [7]: par_list == child_list
Out[7]: True

In [8]: par_list is child_list
Out[8]: True

In [9]: par_list
Out[9]: [1, 2, 3, 4, 5]

In [10]: par_list[2] = 'Udhay'

In [11]: par_list
Out[11]: [1, 2, 'Udhay', 4, 5]

In [12]: child_list
Out[12]: [1, 2, 'Udhay', 4, 5]

In [13]: child_list[0] = "Prakash"

In [14]: child_list
Out[14]: ['Prakash', 2, 'Udhay', 4, 5]

In [15]: par_list
Out[15]: ['Prakash', 2, 'Udhay', 4, 5]

In [16]: # As they are pointing to the same object, changing any of them, is reflect

In [17]: # Now, let us compare this Hard COPY with Shallow COPY and Deep COPY

In [18]: import copy

In [19]: #shallow copy ----copy.copy()

In [20]: #Deepcopy=========copy.deepcopy()

In [21]: # Let us reassign the values

In [22]: par_list=[1,2,3,4,5]

In [23]: child_list1 = par_list

In [24]: child_list2=copy.copy(par_list)

In [25]: child_list3=copy.deepcopy(par_list)

In [26]: par_list==child_list1==child_list2==child_list3
Out[26]: True

In [27]: par_list is child_list1 is child_list2 is child_list3
Out[27]: False

In [28]: par_list is child_list1
Out[28]: True

In [29]: (par_list is child_list1, par_list is child_list2, par_list is child_list3)
Out[29]: (True, False, False)

In [30]: help(id)
Help on built-in function id in module __builtin__:

id(...)
    id(object) -> integer

    Return the identity of an object.  This is guaranteed to be unique among
    simultaneously existing objects.  (Hint: it's the object's memory address.)


In [31]: (id(par_list), id(child_list1), id(child_list2), id(child_list3))
Out[31]: (51084984, 51084984, 51099888, 51084824)

In [32]: par_list
Out[32]: [1, 2, 3, 4, 5]

In [33]: par_list[3] = "new"

In [34]: par_list
Out[34]: [1, 2, 3, 'new', 5]

In [35]: par_list, child_list1, child_list2, child_list3
Out[35]: ([1, 2, 3, 'new', 5], [1, 2, 3, 'new', 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5]

In [36]: # Only HardCOPYed list is effected

In [37]: # It is an advantage in some cases.

In [38]: # To investigate the difference between shallow copy and deepcopy, get us g

In [39]: par_list=[1,2,3,[4,5,[6,7]]]

In [40]: par_list
Out[40]: [1, 2, 3, [4, 5, [6, 7]]]

In [41]: child_list2=copy.copy(par_list) #shallow COPY

In [42]: child_list3=copy.deepcopy(par_list) #Deep COPY

In [43]: par_list
Out[43]: [1, 2, 3, [4, 5, [6, 7]]]

In [44]: child_list2
Out[44]: [1, 2, 3, [4, 5, [6, 7]]]

In [45]: child_list3   #Deep COPY
Out[45]: [1, 2, 3, [4, 5, [6, 7]]]

In [46]: par_list is child_list2 #shallow COPY
Out[46]: False

In [47]: par_list is child_list3 #Deep COPY
Out[47]: False

In [48]: par_list == child_list2 #shallow COPY
Out[48]: True

In [49]: par_list == child_list3 #Deep COPY
Out[49]: True

In [50]: par_list[3][2][1]
Out[50]: 7

In [51]: par_list[3][2][1] = "seven"

In [52]: par_list
Out[52]: [1, 2, 3, [4, 5, [6, 'seven']]]

In [53]: child_list2   #shallow COPY
Out[53]: [1, 2, 3, [4, 5, [6, 'seven']]]

In [54]: child_list3   #Deep COPY
Out[54]: [1, 2, 3, [4, 5, [6, 7]]]

Verifying with single dimension lists
In [59]: par_list = [1,2,3,4]

In [60]: pa
%page     par_list  pass      %paste    %pastebin

In [60]: child_list1 = par_list

In [61]: child_list2 = copy.copy(par_list)

In [62]: child_list3 = copy.deepcopy(par_list)

In [63]: par_list[2]= "two"

In [64]: par_list
Out[64]: [1, 2, 'two', 4]

In [65]: child_list1
Out[65]: [1, 2, 'two', 4]

In [66]: child_list2
Out[66]: [1, 2, 3, 4]

In [67]: child_list3
Out[67]: [1, 2, 3, 4]

CONCLUSION: In single dimension lists, if you do not want the copied list not to get affected to the changes in source list, go for shallow COPY.
 In multi-dimension lists, if you do not want the copied list not to get affected to the changes in source list, go for Deep COPY.


click here for video tutorial

Sunday, July 5, 2015

Difference between pass, continue and break in python

pass vs continue vs break in python 

In Python, Pass, Continue and break are used to loops.

Though continue and break are similar to that of other traditional programming languages, pass is a unique feature available in python.

break   - Terminates the loop, after its invocation.
continue- Skips the current loop, and continues perform the next consecutive loops.
pass      - Does nothing. No logic to work. No break nor skipping a loop. pass is placed when there is no logic to be written for that condition, within the loop. It is advantageous for the developers for writing the logic in future.

The following example illustrates their difference:

1:  #!usr/bin/env python  
2:  print "\nExample to illustrate CONTINUE \n"  
3:  for j in range(10):  
4:    if j==5:  
5:      continue  
6:    print j,  
7:  print "\nExample to illustrate BREAK \n"  
8:  for p in range(10):  
9:    if p==5:  
10:      break  
11:    print p,  
12:  print "\nExample to illustrate PASS \n"  
13:  for i in range(10):  
14:    if i==5:  
15:      pass  
16:    print i,  

OUTPUT:

>>>

Example to illustrate CONTINUE

0 1 2 3 4 6 7 8 9
Example to illustrate BREAK

0 1 2 3 4
Example to illustrate PASS

0 1 2 3 4 5 6 7 8 9


Inference: Ex1 skipped printing 5 due to the presence of  continue.
                Ex2 stopped printing from 5 due to the presence of break.
                Ex3  printed all the values, with neither skipping a value nor stopping the loop.

Friday, March 6, 2015

Python: Differences between str() vs repr()


Both str() and repr() are used to represent strings in python.

But, there exists some differences in their representation.

str() return strings which ease human-reading.

repr() return string which can also the read by human-beings,
    but its representation eases the machine.

Observe few differences below:

They differ in displaying the string
>>> s='Hello, world!!!!'
>>> str(s)
'Hello, world!!!!'
>>> repr(s)
"'Hello, world!!!!'"
Though both are representing the same string, they are not logically same.
>>> str(s)==repr(s)
False

But, str(repr()) and repr(str()), both are finally equal
>>> str(repr(s))
"'Hello, world!!!!'"
>>> repr(str(s))
"'Hello, world!!!!'"
>>> repr(str(s))==str(repr(s))
True

Note the number of digits after decimal point, being represented for floating-point values,by both of them.
>>> str(1.0/7.0)
'0.142857142857'
>>> repr(1.0/7.0)
'0.14285714285714285'

Observe the presence and absence of effect of escape sequences, in printing a str() and repr() based strings, respectively.
>>> s="Hello\nworld"
>>> print str(s)
Hello
world
>>> print repr(s)
'Hello\nworld'

Sunday, February 22, 2015

How to Install Linux?


 Linux Installation Procedure


On request from my readers, i am posting the linux installation procedures. You are free to choose anny one of these FIVE procedures.

Linux operating system is available in numerous flavors, such as Debian,
Ubuntu, Fedora, RedHat, etc.

PROCEDURES:

I. Slick and go: You can install it on your hard disk and completely erase the current disk, which will wipe out your Windows install. This isn't recommended unless you are installing Linux on an older computer that isn't critical to your business. Or if you are really ready for a change and are into new and exciting things...

II. Dual-Boot: Another way is to install Linux alongside your current Windows install and then decide which one you want to use at bootup. This is a popular route because you can always go back to Windows if you need something. This is recommended because there will be growing pains when you start to use Linux. Linux can do anything that Windows can do, but it is not Windows. Once you get used to Linux, you'll never go back, but sometimes getting to that point is difficult. Dual-booting can ease the transition and give the new Linux user a safety net.

III. Boot from USB flash drive: Install Linux on a USB stick and eliminate the risk of hurting your current Windows setup. This USB stick acts as a hard disk. This is a nice option because it has all of the advantages to the Dual-Boot option, and you can carry your Linux distro with you whereever you go. Then any computer at work or home or your friend's house is your Linux box.

IV. New HD: Another "safe" way to get into Linux is to either buy a new harddrive, or grab a used one, and install Linux on the new HD. Take the old drive out, carefully store it somewhere safe, put the "new" drive in and install Linux. If at any point you want to go back to your Windows system, then just swap out drives. This is a nice way to go because it is safe, and it is easy.

V. Super Easy: Simply use the Wubi installer. check your system architecture (32/64 bit), and download Wubi.exe correspondingly. Installation is same as installing an application in windows. Just click next,next...ok. Restart the system, find options to choose between windows and linux. choose linux and play with it.

Saturday, February 21, 2015

Python Facts


Python Facts
Python Facts

Python is a WYSIWYG language--what you see is what you get because the way code looks in the way it runs, regardless of who coded it.

Python2 is backward compatible; whereas Python3 is backward INCOMPATIBLE.
Python supports OOPs concepts. But, in python, both private and protected modes are having same authority. This is the only limitation in python becoming complete OOP language.
Python interpreter generates byte-code, so the python applications are platform-independent.
Python runs faster than java, but slower than C language.
Python was written in C language.
Pre/Post increment/decrement like x++,x--,--x,++x, are INVALID in python
Compound operations such as +=,-=,*=,/= are VALID in Python
Python is case-sensitive i.e., variable “work” is different from variable “Work”, or “WORK
Using underscores (eg:price_at_opening) and Camel-casing (eg:PriceAtOpening)is VALID
Multiple Assignments are VALID in python.
Ex: x=y=z=1
Parallel assignment (or unpacking) is POSSIBLE in python
Eg: a,b=1,2
(x,y,z)=1,2,3
But,(x,y,z)=12 is not possible.
In python 2, Print is a statement. In python 3, print is a function.
To use print() function of python 3 in python2, place this statement in the first lines of script:
from __future__ import print_function
= assignment operator
== Operator to check value equivalence
is Operator to check identity of objects; looks at object level
in Operator to check identity of objects; looks at index level
!= not-equal-to operator
<> not-equal-to operator. Available only in python2.
# comment operator in python; called as octothorpe/pound/hash/mesh
>>> Input operator, shows readiness of interpreter. Called as chevron
^ bit-wise operator. Not power operator. Called as caret
; used to separate TWO or more statements in the same line.
‘‘‘ ’’’ or “““ ””” docstrings. Used for multiple-line comment in python scripts. Differs from using #. Appears in the output. Useful, especially, in modules.
#! Called shebang. Used as the first character in python script.
\ line-continuation operator. Used when a statement spans more than one line.
Eg: print “Udhay\
Prakash”
() used for tuples
[] used for lists
{} used for dictionaries
([]) used for sets
Switch-case condition is not defined in python. Instead, If-elif-else ladder can be used. Also, dictionary of functions can be used.
Eg:
>>> result={
... 'a':lambda x :x*5,
... 'b':lambda x:x+7,
... 'c':lambda x:x-2}
>>> result['b'](10)
17
Indentation is both boon and bane (for beginners) for python. Use spaces instead of Tabs in scripts.
Eg:
>>> a=2
>>> a
2
>>> a=2
Traceback ( File "<interactive input>", line 1
a=2
^
IndentationError: unexpected indent

Running python with –t option prints warning messages when tabs and spaces are mixed inconsistently within the same program block.
Running python with –tt option turns these warning messages in to TabError exception.
raw_input() takes any input as string type.
input() takes any input type dynamically.
&&,|| are defined operators in python
and boolean operator for AND operation
or boolean operator for OR operation
not Boolean operator for NOT operation
set operators
| union operator for sets
& intersection operator for sets
  • Set difference operator
Eg: c=t-s# set c contains items in set t, but not in set s
^ Symmetric difference operator for sets
Eg: d=t^s # set d contains items in set t or set s, but not common items in both.




bitwise Operators
& bit-wise AND operator
| bit-wise OR operator
^ bit-wise XOR operator
~ bit-wise invert operator. Eg: ~5 results in -6
Bit-wise invert of x is –(x+1)
>> left shift operator
Eg: 15>>1
7
Explanation: 15-1111 (in 8421 convention)
15>>1 means shifting one position left.
It becomes 0111 i.e., 7
<< right shift operator
** power of operator
/ division operator
// floor division operator (only in python3)
% modulo operator. Returns remainder of a division.

PEP8 suggests (not mandatory) for a white space around any operator.
It is suggested to define default parameters in the last, for functions.


By default, Python source files are treated as encoded in UTF-8.
To use different encoding for source files, it must be specified in the second line, after #! line, in the script.
Format: # -*- coding: encoding -*-

When you use Python interactively, it is frequently handy to have some standard commands executed every time the interpreter is started. You can do this by setting an environment variable named PYTHONSTARTUP to the name of a file containing your start-up commands. This is similar to the .profile feature of the Unix shells.

range(init_value,final_value,step_size)returns integers from init_value, till final_value, in steps of step_size. It doesn’t include final_value. The step_size MUST be either positive or negative integer; not a float value.

xrange() is same as range(); but, results in values only when essential. Available only in python2.

Python supports range() data-type. So, xrange() is not required.
{} are used to create both a dictionary type and set type.
Set contains only (unrepeated) elements; whereas dictionary contains keys and elements. Keys can’t be repeated, but elements in dictionary can be repeated.

Empty set must be created as var_name=set(), instead of var_name={}. The later creates an empty dict type variable.

When the Python interpreter is invoked with -O flag, code optimized .pyo files, are generated. This optimizer only removes assert statements. When -O is used, all bytecode
is optimized; .pyc files are ignored and .py files are compiled to optimized bytecode.

Similarly, passing two -O flags to the Python interpreter (-OO) will cause the bytecode compiler to perform optimizations. Currently only __doc__ strings are removed from the bytecode, resulting in more compact .pyo files.

Only difference between
.pyc and .pyo code is the speed with which they are loaded.

The module compileall can create .pyc files (or .pyo files when -O is used) for all modules in a directory.

One space will be added between arguments, when print function/statement is used, in py3/py2 respectively.

Str.zfill() pads a numeric string on the left with zeros. It understands both plus and minus signs.
Eg:
>>> '23'.zfill(6)
'000023'
>>> '-3.14'.zfill(6)
'-03.14'
>>> '-3.14'.zfill(8)
'-0003.14'

Str.format()
>> print "This is {} and {}".format('GOOD','BAD')
This is GOOD and BAD
>> print "This is {1} and {0}".format('GOOD','BAD')
This is BAD and GOOD
>>print "This {food} is {adjective}".format(food='RICE',adjective="THE BEST ")
This RICE is THE BEST


>>> ord('a')
97
>>> chr(97)
'a'
>>> '\u011f'
'ğ'

Hidden precision Limitation for python:
>>> 0.1+0.1
0.2
>>> 0.1+0.1+0.1
0.30000000000000004
>>> 0.1+0.1+0.1+0.1
0.4
It is recommended not to follow precision values.

Python can store any large number. Practically, it depends on the system memory of the machine.

Float is not exact.
>>> 4294967296.0**2
1.8446744073709552e+19
>>> 4294967296**2
18446744073709551616
1.8446744073709552×101918446744073709552000- 18446744073709551616=384
Float can be accurate upto 17 significant figures.

floating point numbers have limits both in terms of the largest and smallest numbers they can contain.
In total, floating point values have limited size and limited precision.

Textual comparison
>>> 'cat'<'dog'#Alphabetic ordering
True
>>> 'Cat'<'cat'#Uppercase before lowercase
True
>>> 'Dog'<'cat'#All uppercase before lowercase
True
Note: Ordering text is called “collation”, and is a complicated field. Python inequalities use Unicode character numbers for collation.

Order of precedence for OPERATIONS:
From highest to least:

x**y -x +x x%y x/y x*y x-y x+y x==y x!=y x>=y x>y x<=y x<y
not x x and y x or y

>>> -3**2 #** has higher precedence, compared to -
-9
>>> (-3)**2
9
All the operators except ** are left-associated, that means that the application of the
operators starts from left to right.

Unpacking
>>> a,b=10,7
>>> (a,b)=(a+b,a-b)#tuples
>>> a,b
(17, 3)
>>> a,b=a+b,a-b #lists
>>> a,b
(20, 14)

Four spaces’ indentation indicates a “block” of code in python. This can be observed in any for, while….blocks

The immutability of tuples means they’re faster than lists.

Lists
>>> l=[1,2,[3,4,[5,6,7]]]
>>> len(l)
3
No arithmetic operation can be performed between lists.
+ acts as a appending operator
>> a=[1,2]
>>> b=[2,3]
>>> a+b
[1, 2, 2, 3]
>>> a*3
[1, 2, 1, 2, 1, 2]

Note: All these facts are written after thorough verification. I request the readers to comment any modifications and suggestions.