Python Programming

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

KNC402

PYTHON PROGRAMMING

UNIT 1

Python is an interpreter object-oriented, high-level programming languagewith.


dynamicsemanties. Its high-level built in data structures, combined with dynamic
yping and dynamic binding, make it very attractive for RapidApplication

Development, as well as for use as a seripting or glue language to connect existing

components together. Python's simple, easy to learn syntax emphasizes readability

and therefore reduces the cost of program maintenance. Python supports modules and

packages, which encourages program modularity and code reuse. The Python
interpreter and the extensive standard library are available in source or binary form
without charge for all major platforms, and can be freely distributed.

Often, programmers fall in love with Python because of the increased productivity it provides
Since there is no compilation step, the edit-test-debug cycle is incredibly fast. Debugging Python

programs is easy: a bug or bad input will never cause a segmentation fault. Instead, when the
interpreter discovers an error, it raises an exception. When the program doesn't catch the

exception, interpreter prints a stack trace. A source level debugger allows inspection of local
the

and global variables, evaluation of arbitrary expressions, setting breakpoints, stepping through
the code a line at a time, and so on. The debugger i_ written in Python itself, testifying to

Python's introspective power. On the other hand, often the quickest way to debug a program is to
add a few print statements to the source: the fast edit-test-debug cycle makes this simple

approach very effective.


Explain how python is interpreted.

Python program runs directly from the source code.

Each time Python programs are executed code is required.

Byte Coc
-

Python converts source code written by the programmer into intermediate language which is
again translated into the native language / machine language that is executed. So Python is an
Interpreted language.

It is processed at runtime by the interpreter.

- The program need not be compiled before its execution.

- It is similar to PERL and PHP.

- Python is also interactive where it can prompt and interact with the interpreter directly to write

the programs.

which encapsulates the code within the


-
It supports the object-oriented style of the technique

objects.

DYNAMIC SEMANTICS

that its variables are dynamic objects. Essentially,


Python usesdynamic semantics, meaning
a high-level language.
it's just another aspect of Python being

low-level language like C requires you to statically define


In the list example above, a
integer x, set x =
3, and then setx =
"pants'", the
the type of a variable. So if you defined an

Python to set x =
3, Python knows x is an
However, if you use
computer will get very confused.
"pants", Python knows that x is now a string.
integer. If you then set =
x
DYnamic typing defers the determination of the class that an object belongs to until the program
is executing.

Dynamic typing means that the type of the variable is determined only during runtimel Due

to strong typing. types need to be compatible with respect to the operand when performing

operations. For example Python allows one to add an integer and a floating point number, but

adding an integer to a string produces error

Dynamic bindingdefers the determination of the actual method to invoke on an object until
program execution time. Al 4he time o execuion variabl
unchon bindto each othiv
#Let us assign some integer value to a variahle
X=10

print(type(X))
X="Hello"

print(typeX))
Gives the output:
class 'int' >

<class 'str'>

What is the Programming Cycle for Python?

shorter than that of traditional tools. There are


The development cycle of Python is considerably
no compilation or linking steps
in Python. Python programs simply import modules at runtime

and use the objects they contain. Because of this, Python programs run immediately after
changes are made. Also because Python is interpreted, there's a rapid turnaround after program
changes. And because Python's parser is embedded in Python-based systems, it's easy to modify

programs at runtime.
Python is based on C and C++. Python's core is completely written in a mix of both C and
additionalC++ Libraries as add-ins such as Qt. Wix. Win32
among hundreds more.
How well Python can Cycle. just have a look at programs such as DropBox and or Blender
Render(with the BE-Game Engine) and are nonetheless massive.

Many fail to recognize that Python executes fully as an already compiled C Language with tie
ins C++ Libraries along with any Language that makes use of the C, C++ Languages argv, arge

parsing of the Operating Systems Command-Line through any Shell Program by those likewise.

Traditional programming cycle Vs Programming cycle for

python
Python programming cycle Traditional programming cycle

STEP #1 RUN THE APPLICATION RUN THE APPLICATION

TEST THE APPLICATION TEST THE APPLICATION


STEP #2

EDIT SORUS CODE AGAIN


STEP #3 EDIT SORUSCODE AGAIN
STEP # 4 SKIP THIS STEP RECOMPILE

STEP #5 SKIP THIS STEP RE-LINK

STEP #6 REPEAT (IF NEEDED) REPEAT (IF NEEDED)

Explain the programming cycle for Python.


Answer
is dramatically shorter than that of traditional programming cycle.
1. Python's programming cycle
2. In Python, there are no compile or link steps.
modules at runtime and use the objects
3. Python programs simply import
run immediately after changes are made.
contain. Because of this, Python programs
they
module reloading can be used, it is even possible
4. In cases where dynamic
to
change and reload parts of a running
program without stopping it at all.
5. Python's
impact on the programming cycle is as follows:

(Start the application)-


(Start the application
Test behavior
Test behavior
Stop the application
Edit program code
Edit program code
(b) Python's programming cycle
(a) Python's programming cycle with module reloading
Since Python is interpreted, there is a rapid turnaround after program changes. And because Python's
parser is embedded in Python-based

systems, it is easy to modify programs at runtime

What is IDE ? Discuss some Python IDE.


Answer

1. IDE is a software package that consists of several tools for developing and testing the software
2. An IDE helps the developer by automating the process.

3. IDEs integrate many tools that are designed for SDLC.

4 1DEs were introduced to diminish the coding and typing e

5. Some of the Python IDEs are:

be more productive and provides smart suggestions. It


a.PyCharm: PyCharm assists the developers to
saves time by taking care of routine tasks,
hence increases productivity.

Features of PyCharm:
i It has smart code navigation, good code editor, a function for quick refactoring.

ii. The activities with PyCharm are profiling, testing, debugging, remote development, and
integrated
deployments
JS, JavaScript, CSS, HTML and live
ii. PyCharm supports Python web development frameworks, Angular
editing functions.
to create a secure and
is widely used for data science works. It is mostly used
b. Spyder : Spyder can add
Python. Spyder Python uses (Python plug-in) which a developer
Pyat
scientific environment for
as an extension.

Features of Spyder
and auto code completion
i. It has good syntax highlighting

features
and edits variables directly from GUI.
i. Spyder Python explores
multi-language editor
ii. It performs very well in

It is external plug-in for Eclipse and is very popular as Python interpreter.


c. PyDev : an

Features of PyDev :
code
has parameters like refactoring, debugging. type hinting, code analysis, and
i. PyDev strong
coverage function.
remote debugger, Unittest
interactive console,
i. PyDev supports tokens browser, PyLint integration,
integration, etc.

IDLE is a basic IDE by beginnerlevel developer.


mainly used
d. IDLE:
increases the flexibility for users.
i. IDLE Python is a cross-platform IDE, hence it
collaboration with Tkinter GUI toolkit.
i. It is developed only in Python in
great functions like smart indentation, call
text editor in IDLE has some
ii. The feature of multi-window
and undo option.
tips, Python colorizing,
various platforms and has its own marketplace for
e. Visual studio : It enables development for

extensions.

Features ofvisual studio:

in visual studio, debugging, and other activities.


i. It supports Python coding
features.
versions in the market with great
i. It has both paid and free

You might also like