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:
- 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 on type bool are:
|A||B||A and B||A or B||not A|
Variables and Assignments in Python
- Variables give a way to assign names to objects. Consider the code below.
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, ﬁnally, 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
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
- 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 IDEs||Proprietary Python IDEs|
|Pydev with Eclipse||PyCharm (used by Twitter & Groupon)|
|Spyder Python (best suited for scientific usage of python)||PTVS (Python Tools for Visual Studio)|
|Emacs and Anaconda Python IDE|
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.