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:
- 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.
- 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, ﬁ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|
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.
Other Important Topics:
- Python and Other Object-Oriented Programming Languages
- Python 2 vs Python 3
- Introduction to Python Programming
- The Basic Elements of Python Programming
- Branching, Indentation, Looping and Control Structure in Python
- Indexing & Slicing of Strings and Capturing Inputs
- Built-in Data Types and Functions in Python
- Specifications, Global Variables, Modules and Packages in Python
- Working with Files in Python
- Strings in Python
- Lists in Python
- Tuples in Python
- Dictionaries in Python
- Mutable and Immutable Python Objects
- Functions as Objects, map(), filter() and reduce()
- Exception Handling in Python
- Classes and Object Oriented Programming in Python
- Searching Algorithms in Python
- Method Resolution Order (MRO) in Python
- Sorting Algorithms in Python