Wednesday 11 March 2020

Datatypes in Python- Lecture 1


Data Types


Data Type represent the type of data present inside a variable.
In Python we are not required to specify the type explicitly. Based on value provided, the type will be assigned automatically.


Hence Python is Dynamically Typed Language.


Python contains the following inbuilt data types:


1. int  : to store integer values
2. float : to store floating point values and exponential values
3. complex : to store values in the form of a+bj , basically used to store scientific values
4. bool : to store Boolean values True or False
5. str : to store sequence of characters

The above five data types are Fundamental Data types and all of them are Immutable

6. bytes: to store sequence of numbers in range of 0-256, bytes are Immutable
7. bytearray : Mutable version of bytes is bytearray, rest it is same as bytes
8. range:  to store sequence of numbers of specified range. Elements of range are also immutable
9. list: to store multiple heterogenous values in one object
where order of insertion is preserved and
 duplicates are allowed.
lists are Mutable
10. tuple : Immutable version of list is tuple, rest it is same as list
11. set : to store multiple heterogenous values in one object where order of insertion is NOT preserved and
duplicates are not allowed.
Sets are Mutable
12. frozenset :  Mutable version of set
13. dict : to store key- values
14. None means nothing at all



Note: Python contains several inbuilt functions

1.type() to check the type of variable

2. id() to get address of object

3. print() to print the value

In Python everything is object.


For details please go through the above video

 

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