Unit 2 Part1
Unit 2 Part1
Python Programming
ing Problem Solving Approach
Reema Thareja
• It is difficult to pack up a big Python application into a single executable file. This
© OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS
RESERVED.
Applications of Python
• Embedded scripting language: Python is used as an embedded scripting language for
various testing/ building/ deployment/ monitoring frameworks, scientific apps, and
quick scripts.
• 3D Software: 3D software like Maya uses Python for automating small user tasks, or
for doing more complex integration such as talking to databases and asset
management systems.
• Web development: Python is an easily extensible language that provides good
integration with database and other web standards.
GUI-based desktop applications: Simple syntax, modular architecture, rich text
processing tools and the ability to work on multiple operating systems makes Python a
preferred choice for developing desktop-based applications.
• Image processing and graphic design applications: Python is used to make 2D
© OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS
RESERVED.
6
Applications of Python
• Scientific and computational applications: Features like high speed, productivity and
availability of tools, such as Scientific Python and Numeric Python, have made Python a
preferred language to perform computation and processing of scientific data. 3D
modeling software, such as FreeCAD, and finite element method software, like Abaqus,
are coded in Python.
Games: Python has various modules, libraries, and platforms that support development
of games. Games like Civilization-IV, Disney's Toontown Online, Vega Strike, etc. are
coded using Python.
• Enterprise and business applications: Simple and reliable syntax, modules and
libraries, extensibility, scalability together make Python a suitable coding language for
customizing larger applications. For example, Reddit which was originally written 7 in
© OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS
Common Lips, was rewritten in Python in 2005. A large part RESERVED.
of Youtube code is also
Writing and Executing First Python Program
10
Exampl
e:
11
Exampl
e:
12
Exampl
e:
14
15
16
Exampl
e:
17
18
19
20
22
23
Identity Operators
is Operator: Returns true if operands or values on both sides of the operator point to
the same object and false otherwise. For example, if a is b returns 1, if id(a) is same as
25
id(b). © OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS
RESERVED.
is not Operator: Returns true if operands or values on both sides of the operator does
Expressions
An expression is any legal combination of symbols (like variables, constants and
operators) that represents a value. In Python, an expression must have at least one
operand (variable or constant) and can have one or more operators. On evaluating an
expression, we get a value. Operand is the value on which operator is applied.
Constant Expressions: One that involves only constants. Example: 8 + 9 – 2
Integral Expressions: One that produces an integer result after evaluating the
expression. Example:
a = 10
• Floating Point Expressions: One that produces floating point results. Example: a * b / 2
• Relational Expressions: One that returns either true or false value. Example: c = a>b
• Logical Expressions: One that combines two or more relational expressions and returns
26
a value as True or False. Example: a>b && y! = 0 © OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS
RESERVED.
• Bitwise Expressions: One that manipulates data at bit level. Example: x = y&z
Expressions- Operator Precedence
Exampl
es:
29
30
31
32
33
34
35