Imp ques of PYTHON
1. What is python?
• Python is a high-level programming language created by Guido VanRossum
- fondly known as Benevolent Dictator For Life.
• It was first released in 1991
• Python programmers are often called Pythonists or Pythonistas.
2. Where is python used?
• Python is used for multiple purposes. These include:
• System programming
• Building GUI applications
• Internet scripting
• Component integration
• Database programming
• Rapid prototyping
• Numeric and Scientific programming
• Game programming
• Robotics programming
3. What do you mean by programming paradigms?
• Paradigm means organization principle. It is also known as model.
• Programming paradigm/model is a style of building the structure and
elements of computer programs.
• There exist many programming models like Functional, Procedural,
Object-oriented, Event-driven, etc.
• Many languages facilitate programming in one or more paradigms.For
example, Python supports Functional, Procedural, Object-oriented and Event-driven
programming models.
• There are situations when Functional programming is the obvious choice,
and other situations were Procedural programming is the better choice.
• Paradigms are not meant to be mutually exclusive. A single program may
use multiple paradigms.
4. What is Functional Programming Model?
• Functional programming decomposes a problem into a set of functions.
These functions provide the main source of logic in the program.
• Functions take input parameters and produce outputs. Python provides
functional programming techniques like lambda, map, reduce and filter. These are
discussed in Chapter 15.
In this model computation is treated as evaluation of mathematical functions. For
example, to get factorial value of a number, or nth Fibonacci number we can use the
following functions:factorial(n) = 1
if n == 0
= n * factorial(n - 1) if n > 0
fibo(n) = 0
= 1
if n = 0
if n = 1
= fibo(n - 2) + fibo(n - 1)
if n > 1
• The output value of a function depends only on its arguments, so
calling a function with the same value for an argument always produces the same
result. As a result, it is a good fit for parallel execution.
• No function can have side effects on other variables (state remains
unaltered).
• Functional programming model is often called a 'Declarative'
programming paradigm as programming is done with expressions or declarations
instead of statements.
5. What is Procedural Programming Model?
• Procedural programming solves the problem by implementing one statement
(a procedure) at a time. Thus it contains explicit steps that are executed in a
specific order.
• It also uses functions, but these are not mathematical functions like
the ones used in functional programming. Functional programming focuses on
expressions, whereas Procedural programming focuses on statements.
• The statements don't have values and instead modify the state of some
conceptual machine.
• Same language expression can result in different values at different
times depending on the global state of the executing program. Also, the functions
may change a program's state.
• Procedural programming model is often called 'Imperative' programming
as it changes state with an explicit sequence of statements.
6. What is Object-oriented Programming Model?
• This model mimics the real world by creating inside the computer a
mini-world of objects.
• In a University system objects can be VC, Professors, Non-teaching
staff, students, courses, semesters, examinations, etc.
• Each object has a state (values) and behavior (interface/methods).
Objects get state and behavior based on the class from which it created.
• Objects interact with one another by sending messages to each other,
i.e. by calling each other's interface methods.
7. What is Event-driven Programming Model?
• This model is popularly used for programming GUI applications
containing elements like windows, check boxes, buttons, combo-boxes, scroll bars,
menus, etc.
• When we interact with these elements (like clicking a button, or moving
the scrollbar or selecting a menu item) events occur and these elements emit
messages. There are listener methods which are registered with these GUI elements
which react to these events.
• Since there is no guaranteed sequence in which events may occur (based
on how we interact with GUl elements), the listeners should be able to handle them
in asynchronous manner.