Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Python Notes For 12th Class

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Python Notes for 12th class

Guido Van Rossum, a Dutch programmer, created Python programming


language. In the late 80's, he had been working on the development of ABC
language in a computer science research institute named Centrum
Wiskunde & Informatica (CWI) in the Netherlands. In 1991, Van Rossum
conceived and published Python as a successor of ABC language.
Being the principal architect of Python, the developer community conferred
upon him the title of Benevolent Dictator for Life (BDFL). However, in
2018, Rossum relinquished the title. Thereafter, the development and
distribution of the reference implementation of Python is handled by a
nonprofit organization Python Software Foundation.

Major Python Releases


Following are the important stages in the history of Python −

Python 0.9.0

Python's first published version is 0.9. It was released in February 1991. It


consisted of support for core object-oriented programming principles.

Python 1.0

In January 1994, version 1.0 was released, armed with functional


programming tools, features like support for complex numbers etc.

Python 2.0

Next major version − Python 2.0 was launched in October 2000. Many new
features such as list comprehension, garbage collection and Unicode support
were included with it.

Python 3.0

Python 3.0, a completely revamped version of Python was released in


December 2008. The primary objective of this revamp was to remove a lot
of discrepancies that had crept in Python 2.x versions. Python 3 was
backported to Python 2.6. It also included a utility named as python2to3 to
facilitate automatic translation of Python 2 code to Python 3.

EOL for Python 2.x


Even after the release of Python 3, Python Software Foundation continued to
support the Python 2 branch with incremental micro versions till 2019.
However, it decided to discontinue the support by the end of year 2020, at
which time Python 2.7.17 was the last version in the branch.
Current Version
Meanwhile, more and more features have been incorporated into Python's
3.x branch. As of date, Python 3.11.2 is the current stable version, released
in February 2023.

What's New in Python 3.11?


One of the most important features of Python's version 3.11 is the
significant improvement in speed. According to Python's official
documentation, this version is faster than the previous version (3.10) by up
to 60%. It also states that the standard benchmark suite shows a 25% faster
execution rate.

Features of Python
Let's highlight some of the important features of Python that make it widely
popular. Apart from these 10 features where are number of other interesting
features which make Python most of the developer's first choice.

2) Writing our first program:

Just type in the following code after you start the interpreter.

# Script Begins

print("GeeksQuiz")

# Scripts Ends

Output:
GeeksQuiz
Let’s analyze the script line by line.
Line 1: [# Script Begins] In Python, comments begin with a #. This
statement is ignored by the interpreter and serves as documentation for our
code.
Line 2: [print(“GeeksQuiz”)] To print something on the console, print()
function is used. This function also adds a newline after our message is
printed(unlike in C). Note that in Python 2, “print” is not a function but a
keyword and therefore can be used without parentheses. However, in Python
3, it is a function and must be invoked with parentheses.
Line 3: [# Script Ends] This is just another comment like in Line 1.
Python designed by Guido van Rossum at CWI has become a widely used
general-purpose, high-level programming language.
Prerequisites:
Knowledge of any programming language can be a plus.

Reason for increasing popularity

1. Emphasis on code readability, shorter codes, ease of writing


2. Programmers can express logical concepts in fewer lines of code in
comparison to languages such as C++ or Java.
3. Python supports multiple programming paradigms, like object-
oriented, imperative and functional programming or procedural.
4. There exists inbuilt functions for almost all of the frequently used
concepts.
5. Philosophy is “Simplicity is the best”.

LANGUAGE FEATURES

 Interpreted
 There are no separate compilation and execution steps like C
and C++.
 Directly run the program from the source code.
 Internally, Python converts the source code into an
intermediate form called bytecodes which is then translated
into native language of specific computer to run it.
 No need to worry about linking and loading with libraries, etc.
 Platform Independent
 Python programs can be developed and executed on multiple
operating system platforms.
 Python can be used on Linux, Windows, Macintosh, Solaris and
many more.
 Free and Open Source; Redistributable
 High-level Language
 In Python, no need to take care about low-level details such
as managing the memory used by the program.
 Simple
 Closer to English language;Easy to Learn
More emphasis on the solution to the problem rather than the
syntax
 Embeddable
 Python can be used within C/C++ program to give scripting
capabilities for the program’s users.
 Robust:
 Exceptional handling features
 Memory management techniques in built
 Rich Library Support
 The Python Standard Library is very vast.
 Known as the “batteries included” philosophy of Python ;It
can help do various things involving regular expressions,
documentation generation, unit testing, threading, databases,
web browsers, CGI, email, XML, HTML, WAV files,
cryptography, GUI and many more.
 Besides the standard library, there are various other high-
quality libraries such as the Python Imaging Library which is
an amazingly simple image manipulation library.
Python vs JAVA
Python Java

Dynamically Typed Statically Typed


 No need to declare anything. An  All variable names (along with their types)
assignment statement binds a must be explicitly declared. Attempting to
name to an object, and the object assign an object of the wrong type to a
can be of any type. variable name triggers a type exception.
 No type casting is required  Type casting is required when using
when using container objects container objects.

Concise Express much in limited words Verbose Contains more words

Compact Less Compact

Uses Indentation for structuring code Uses braces for structuring code

The classical Hello World program illustrating the relative verbosity of a


Java Program and Python Program

Java Code
public class HelloWorld
{
public static void main (String[] args)
{
System.out.println("Hello, world!");
}
}
Python Code
print("Hello, world!")

Python - Interpreter

Python is an interpreter-based language. In a Linux system, Python's


executable is installed in /usr/bin/ directory. For Windows, the executable
(python.exe) is found in the installation folder (for example C:\python311).
Python code is executed by one statement at a time method. Python
interpreter has two components. The translator checks the statement for
syntax. If found correct, it generates an intermediate byte code. There is a
Python virtual machine which then converts the byte code in native binary
and executes it. The following diagram illustrates the mechanism:

Python interpreter has an interactive mode and a scripted mode.

Python Interpreter - Interactive Mode


When launched from a command line terminal without any additional
options, a Python prompt >>> appears and the Python interpreter works on
the principle of REPL (Read, Evaluate, Print, Loop). Each command
entered in front of the Python prompt is read, translated and executed. A
typical interactive session is as follows.

>>> price = 100


>>> qty = 5
>>> total = price*qty
>>> total
500
>>> print ("Total = ", total)
Total = 500
To close the interactive session, enter the end-of-line character (ctrl+D for
Linux and ctrl+Z for Windows). You may also type quit() in front of the
Python prompt and press Enter to return to the OS prompt.

You might also like