Difference between revisions of "Python"
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
		
	
 (Added Python 2/3 introduction.)  | 
				 (Described differences between Python 2 and 3 and show examples.)  | 
				||
| Line 1: | Line 1: | ||
Welcome to the Python programming page.  The Python language has evolved greatly over the year.  Python 2 is nice for scripting and simpler tasks.  Python 3 is a more substantial Object Oriented Programming Language.  Most of the details herein will focus on Python 3.  However, if there is any Python 2 examples included they will be designated as such.  The reason for this is because there are a large number of syntax differences and each requires it's own interpreter.  '''Python 2 has more complicated syntax than Python 3'''. Python 3 has an easier syntax compared to Python 2. A lot of libraries of Python 2 are not forward compatible. A lot of libraries are created in Python 3 to be strictly used with Python 3.  | Welcome to the Python programming page.  The Python language has evolved greatly over the year.  Python 2 is nice for scripting and simpler tasks.  Python 3 is a more substantial Object Oriented Programming Language.  Most of the details herein will focus on Python 3.  However, if there is any Python 2 examples included they will be designated as such.  The reason for this is because there are a large number of syntax differences and each requires it's own interpreter.  '''Python 2 has more complicated syntax than Python 3'''. Python 3 has an easier syntax compared to Python 2. A lot of libraries of Python 2 are not forward compatible. A lot of libraries are created in Python 3 to be strictly used with Python 3.  | ||
== KEY DIFFERENCES ==  | |||
* Python 3 syntax is simpler and easily understandable whereas Python 2 syntax is comparatively difficult to understand.  | |||
* Python 3 default storing of strings is Unicode whereas Python 2 stores need to define Unicode string value with “u.”  | |||
* Python 3 value of variables never changes whereas in Python 2 value of the global variable will be changed while using it inside for-loop.  | |||
* Python 3 exceptions should be enclosed in parenthesis while Python 2 exceptions should be enclosed in notations.  | |||
* Python 3 rules of ordering comparisons are simplified whereas Python 2 rules of ordering comparison are complex.  | |||
* Python 3 offers Range() function to perform iterations whereas, In Python 2, the xrange() is used for iterations.  | |||
{| class="wikitable"  | |||
!Basis of comparison  | |||
!Python 3  | |||
!Python 2  | |||
|-  | |||
|Release Date  | |||
|2008  | |||
|2000  | |||
|-  | |||
|Function print  | |||
|print (“hello”)  | |||
|print “hello”  | |||
|-  | |||
|Division of Integers  | |||
|Whenever two integers are divided, you get a float value  | |||
|When two integers are divided, you always provide integer value.  | |||
|-  | |||
|Unicode  | |||
|In Python 3, default storing of strings is Unicode.  | |||
|To store Unicode string value, you require to define them with “u”.  | |||
|-  | |||
|Syntax  | |||
|The syntax is simpler and easily understandable.  | |||
|The syntax of Python 2 was comparatively difficult to understand.  | |||
|-  | |||
|Rules of ordering Comparisons  | |||
|In this version, Rules of ordering comparisons have been simplified.  | |||
|Rules of ordering comparison are very complex.  | |||
|-  | |||
|Iteration  | |||
|The new Range() function introduced to perform iterations.  | |||
|In Python 2, the xrange() is used for iterations.  | |||
|-  | |||
|Exceptions  | |||
|It should be enclosed in parenthesis.  | |||
|It should be enclosed in notations.  | |||
|-  | |||
|Leak of variables  | |||
|The value of variables never changes.  | |||
|The value of the global variable will change while using it inside for-loop.  | |||
|-  | |||
|Backward compatibility  | |||
|Not difficult to port python 2 to python 3 but it is never reliable.  | |||
|Python version 3 is not backwardly compatible with Python 2.  | |||
|-  | |||
|Library  | |||
|Recently, many developers are creating libraries which you can only use with Python 3.  | |||
|Many older libraries created for Python 2 are not forward-compatible.  | |||
|}  | |||
== Here, are prime reasons for using Python 3.x versions: ==  | |||
* Python 3 supports modern techniques like AI, machine learning, and data science.  | |||
* Python 3 is supported by a large Python developer’s community. Getting support is easy.  | |||
* It is easier to learn Python language compared to earlier versions.  | |||
* Offers Powerful toolkit and libraries  | |||
* Mixable with other languages  | |||
== Python 2 vs. Python 3 Example Code ==  | |||
Python 3  | |||
 def main():  | |||
   print("Hello World!")  | |||
 if __name__== "__main__":  | |||
   main()  | |||
Python 2  | |||
 def main():  | |||
   print "Hello World!"  | |||
 if __name__== "__main__":  | |||
   main()  | |||
Revision as of 15:37, 29 January 2022
Welcome to the Python programming page. The Python language has evolved greatly over the year. Python 2 is nice for scripting and simpler tasks. Python 3 is a more substantial Object Oriented Programming Language. Most of the details herein will focus on Python 3. However, if there is any Python 2 examples included they will be designated as such. The reason for this is because there are a large number of syntax differences and each requires it's own interpreter. Python 2 has more complicated syntax than Python 3. Python 3 has an easier syntax compared to Python 2. A lot of libraries of Python 2 are not forward compatible. A lot of libraries are created in Python 3 to be strictly used with Python 3.
KEY DIFFERENCES
- Python 3 syntax is simpler and easily understandable whereas Python 2 syntax is comparatively difficult to understand.
 - Python 3 default storing of strings is Unicode whereas Python 2 stores need to define Unicode string value with “u.”
 - Python 3 value of variables never changes whereas in Python 2 value of the global variable will be changed while using it inside for-loop.
 - Python 3 exceptions should be enclosed in parenthesis while Python 2 exceptions should be enclosed in notations.
 - Python 3 rules of ordering comparisons are simplified whereas Python 2 rules of ordering comparison are complex.
 - Python 3 offers Range() function to perform iterations whereas, In Python 2, the xrange() is used for iterations.
 
| Basis of comparison | Python 3 | Python 2 | 
|---|---|---|
| Release Date | 2008 | 2000 | 
| Function print | print (“hello”) | print “hello” | 
| Division of Integers | Whenever two integers are divided, you get a float value | When two integers are divided, you always provide integer value. | 
| Unicode | In Python 3, default storing of strings is Unicode. | To store Unicode string value, you require to define them with “u”. | 
| Syntax | The syntax is simpler and easily understandable. | The syntax of Python 2 was comparatively difficult to understand. | 
| Rules of ordering Comparisons | In this version, Rules of ordering comparisons have been simplified. | Rules of ordering comparison are very complex. | 
| Iteration | The new Range() function introduced to perform iterations. | In Python 2, the xrange() is used for iterations. | 
| Exceptions | It should be enclosed in parenthesis. | It should be enclosed in notations. | 
| Leak of variables | The value of variables never changes. | The value of the global variable will change while using it inside for-loop. | 
| Backward compatibility | Not difficult to port python 2 to python 3 but it is never reliable. | Python version 3 is not backwardly compatible with Python 2. | 
| Library | Recently, many developers are creating libraries which you can only use with Python 3. | Many older libraries created for Python 2 are not forward-compatible. | 
Here, are prime reasons for using Python 3.x versions:
- Python 3 supports modern techniques like AI, machine learning, and data science.
 - Python 3 is supported by a large Python developer’s community. Getting support is easy.
 - It is easier to learn Python language compared to earlier versions.
 - Offers Powerful toolkit and libraries
 - Mixable with other languages
 
Python 2 vs. Python 3 Example Code
Python 3
def main():
  print("Hello World!")
  
if __name__== "__main__":
  main()
Python 2
def main(): print "Hello World!" if __name__== "__main__": main()