Introduction to Basic Elements of Python Programming

Guys, in previous post I gave you all the detailed introduction on python. Now, let us learn some of the most basic elements of Python Programming. There are three most basic elements of Python as given below:

  1. Objects
  2. Expressions
  3. Numerical Types
  • Object is the smallest and core thing that Python program manipulate.
  • Every object has type: Scalar or Non-Scalar.
  • Scalar objects are indivisible. Think of them as the atoms of the language. Non-scalar objects, for example strings, lists, tuples and dictionary, have internal structure.
  • Python has four types of scalar objects: int, float, bool and None (similar to void).
  • Objects and operators can be combined to form expressions, each of which evaluates to an object of some type, which we refer as value.
  • The == operator is used to test whether two expressions evaluate to the same value, and the != operator is used to test if two expressions evaluate to different values.
  • Shell Prompt symbol is >>> which indicates, interpreter is expecting the user to enter some code of python in shell.

Although, most operators in Python work similar to other languages, let us have a look over operators in Python on int and float type in Python:

Operators - int and float

Operators on type bool are:

ABA and BA or Bnot A
FalseFalseFalseFalseTrue
FalseTrueFalseTrueTrue
TrueFalseFalseTrueFalse
TrueTrueTrueTrueFalse

Variables and Assignments in Python

  • Variables give a way to assign names to objects. Consider the code below.
Click here to copy the code
  • A variable is only a name, in python.
  • An assignment statement associates the name to the left of the = symbol with the object denoted by the expression to the right of the =.
  • An object can have one, two or more names associated with it , or also object can have no name associated with it.

Keywords/Reserved Words in Python

and,  with,    for,   is,   raise,   assert,   from,    del,   return,   break,   else,   global,   lambda,    not,   try,   except,   if,   elif,    or,   class,    while,   continue,   exec,   import,   finally,    pass,   as,    yield,   def,   in,   print

Comments and Multiple Assignments in Python

  • # is used to comment in Python.
  • Multiple Assignments is possible in Python which makes swapping very easy.

For example, the code

Click here to copy the code

Now after going through some of the basics of Python, it is now the time for us to start coding in Python and for that we will be requiring an IDE and that is

IDLE

  • It is the Python IDE that comes bundled with Python.
  • Apart from IDLE there are various other Python IDEs, open source as well as proprietary.
Open Source Python IDEsProprietary Python IDEs
Pydev with EclipsePyCharm (used by Twitter & Groupon)
VIMWing IDE
Spyder Python (best suited for scientific usage of python)PTVS (Python Tools for Visual Studio)
Komodo IDE
Eric Python
Emacs and Anaconda Python IDE
IDLE Python

IDLE – Python IDE

That’s all in the basic elements of Python, we covered object types, operators, expressions, variables, assignments, keywords, comments and multiple assignments as well as we introduced IDLE. In next post, I will share some info on working of branching programs in Python.