Monday 24 February 2020

Reserved Words in Python




Reserved Words

Reserved word in any programming language is a word which has some fixed meaning and cannot be redefined by the programmer.

Reserved means “kept for some special purpose”

In Python, some words are reserved to represent some meaning or functionality. 


Such words are called as Reserved words.

There are 33 reserved words available in Python.

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


Note:

1. All Reserved words in Python contain only alphabet symbols.

2. Except the following 3 reserved words, all contain only lower case alphabet symbols.

  • True
  • False
  • None

Eg: a= true ❌

a=True ✅



How we can check the keywords programmatically:

Import the module keyword and check the kwlist attribute

(don’t worry about the meaning of module, everything will be discussed step by step)



>>> import keyword

>>> keyword.kwlist

['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

Python Identifiers




Identifiers

A name in Python program is called identifier. 
It can be class name or function name or module name or variable name.

a = 10
(For detailed concept watch the above video)



Rules to define identifiers in Python:


1. The only allowed characters in Python are:

  • alphabet symbols(either lower case or upper case)
  • digits(0 to 9)
  • underscore symbol(_)

By mistake if we are using any other symbol like $ then we will get syntax error.

  • cash = 10 ✅
  • ca$h =20  ❌

2. Identifier should not starts with digit


  • 123total ❌
  • total123 ✅

3. Identifiers are case sensitive.

 Of course Python language is case sensitive language.

  •  total=10
  •  TOTAL=999
  •  print(total) #10
  •  print(TOTAL) #999

Identifier:

1. Alphabet Symbols (Either Upper case OR Lower case)

2. If Identifier is start with Underscore (_) then it indicates it is private.

3. Identifier should not start with Digits.

4. Identifiers are case sensitive.

5. We cannot use reserved words as identifiers

Example: def=10❌

6. There is no length limit for Python identifiers. But not recommended to use too lengthy identifiers.

7. Dollar ($) Symbol is not allowed in Python.




Q. Which of the following are valid Python identifiers?



1) 123total ❌

2) total123 ✅

3) java2share ✅

4) ca$h ❌

5) _abc_abc_ ✅

6) def ❌

7) if❌



Note:

1.   If identifier starts with _ symbol then it indicates that it is private 

2. If identifier starts with __ (two underscore symbols) indicating that strongly private identifier. 

3. If the identifier starts and ends with two underscore symbols then the identifier is language defined special name, which is also known as magic methods.

E.g.: __add__

private, strongly private are access modifiers, will be discussed in OOP's Concept

Sunday 23 February 2020

Python Versions






Python Version List
Python programming language is being updated regularly with new features and supports. There are lots of updation in python versions, started from 1994 to current release.

A list of python versions with its released date is given below.

Python Version                                          Released Date
Python 1.0                                                 January 1994
Python 1.5                                                 December 31, 1997
Python 1.6                                                 September 5, 2000
Python 2.0                                                 October 16, 2000
Python 2.1                                                 April 17, 2001
Python 2.2                                                 December 21, 2001
Python 2.3                                                 July 29, 2003
Python 2.4                                                 November 30, 2004
Python 2.5                                                 September 19, 2006
Python 2.6                                                 October 1, 2008
Python 2.7                                                 July 3, 2010
Python 3.0                                                 December 3, 2008
Python 3.1                                                 June 27, 2009
Python 3.2                                                 February 20, 2011
Python 3.3                                                 September 29, 2012
Python 3.4                                                 March 16, 2014
Python 3.5                                                 September 13, 2015
Python 3.6                                                 December 23, 2016
Python 3.7                                                 June 27, 2018

Python does not give backward support.
It is not necessary that whatever is available in the previous version that will be automatically be in new version
There are many things in Python 2.0 which is not there in Python 3.0

Major differences between Python 2.0 and Python 3.0

Python- Installation


Features of Python








Features of Python:

1. Simple and easy to learn:
Python is a simple programming language. When we read Python program, we can feel like reading English statements. The syntaxes are very simple and only 30+ keywords are available. When compared with other languages, we can write programs with very less number of lines. Hence more readability and simplicity is there in Python. We can reduce development and cost of the project.

2. Freeware and Open Source:
We can use Python software without any licence and it is freeware.
Its source code is open, so that we can we can customize based on our requirement.
Eg:  Jython is customized version of Python to work with Java Applications.

3. High Level Programming language:
Python is high level programming language and hence it is programmer friendly language. Being a programmer we are not required to concentrate low level activities like memory management and security etc..

4. Platform Independent:
Once we write a Python program, it can run on any platform without rewriting once again. Internally PVM is responsible to convert into machine understandable form.

 5. Portability:
Python programs are portable. i.e. we can migrate from one platform to another platform very easily. Python programs will provide same results on any platform.

 6. Dynamically Typed:
In Python we are not required to declare type for variables. Whenever we are assigning the value, based on value, type will be allocated automatically. Hence Python is considered as dynamically typed language.
But Java, C etc are Statically Typed Languages because we have to provide type at the beginning only.
This dynamic typing nature will provide more flexibility to the programmer.

 7. Both Procedure Oriented and Object Oriented:
Python language supports both Procedure oriented (like C, Pascal etc) and object oriented (like C++, Java) features. Hence we can get benefits of both like security and reusability etc

8. Interpreted:
We are not required to compile Python programs explicitly. Internally Python interpreter will take care of that compilation.
If compilation fails, interpreter raises syntax errors. Once compilation occurs successfully then PVM (Python Virtual Machine) is responsible to execute.

9. Extensible:
We can use other language programs in Python. The main advantages of this approach are:
1. We can use already existing legacy non-Python code
2. We can improve performance of the application

10. Embedded:
We can use Python programs in any other language programs. i.e. we can embed Python programs anywhere.

11. Extensive Library:
Python has a rich inbuilt library. Being a programmer we can use this library directly and we are not responsible to implement the functionality.
etc...

Limitations of Python:

1. Performance wise not up to the mark because it is interpreted language.
2. Not using for mobile Applications

Flavours of Python:

1.CPython: It is the standard flavour of Python. It can be used to work with C language Applications

2. Jython or JPython: It is for Java Applications. It can run on JVM

3. IronPython: It is for C#.Net platform

4.PyPy: The main advantage of PyPy is performance will be improved because JIT compiler is available inside PVM.

5.RubyPython: For Ruby Platforms

6. AnacondaPython: It is specially designed for handling large volume of data processing.