Workshop On Python For Beginners: Hearty Welcomes To
Workshop On Python For Beginners: Hearty Welcomes To
Workshop On Python For Beginners: Hearty Welcomes To
Engineering,
Faculty of Engineering and Technology,
Jain University
Hearty Welcomes to
By,
Deepa.T.P.
Assistant Professor
Dept. of CSE, FET, Jain University
Introduction
• Python is a general-purpose interpreted, interactive, object-oriented, and
high-level programming language.
• It was created by Guido van Rossum during 1985- 1990.
• Like Perl, Python source code is also available under the GNU General
Public License (GPL).
Why Python?
• Python is Interpreted − Python is processed at runtime by the interpreter. You do not need to
compile your program before executing it. This is similar to PERL and PHP.
• Python is Interactive − You can actually sit at a Python prompt and interact with the
interpreter directly to write your programs.
• Python is Object-Oriented − Python supports Object-Oriented style or technique of
programming that encapsulates code within objects.
• Python is a Beginner's Language − Python is a great language for the beginner-level
programmers and supports the development of a wide range of applications from simple text
processing to WWW browsers to games.
Characteristics of Python
• It supports functional and structured programming methods as well as OOP.
• It can be used as a scripting language or can be compiled to byte-code for building large
applications.
• It provides very high-level dynamic data types and supports dynamic type checking.
• It supports automatic garbage collection.
• It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.
Features of Python
• Easy-to-learn − Python has few keywords, simple structure, and a clearly defined syntax. This
allows the student to pick up the language quickly.
• Easy-to-read − Python code is more clearly defined and visible to the eyes.
• Easy-to-maintain − Python's source code is fairly easy-to-maintain.
• A broad standard library − Python's bulk of the library is very portable and cross-platform
compatible on UNIX, Windows, and Macintosh.
• Interactive Mode − Python has support for an interactive mode which allows interactive
testing and debugging of snippets of code.
Features of Python
• Portable − Python can run on a wide variety of hardware platforms and has the same interface on
all platforms.
• Extendable − You can add low-level modules to the Python interpreter. These modules enable
programmers to add to or customize their tools to be more efficient.
• Databases − Python provides interfaces to all major commercial databases.
• GUI Programming − Python supports GUI applications that can be created and ported to many
system calls, libraries and windows systems, such as Windows MFC, Macintosh, and the X Window
system of Unix.
• Scalable − Python provides a better structure and support for large programs than shell scripting.
Python Versions
• MAJOR - Python has two major versions that are not fully compatible: Python 2
and Python 3. For example, 3.5.7, 3.7.2, and 3.8.0 are all part of the Python 3
major version.
• MINOR - These releases are bringing new features and functions. For example,
3.6.6, 3.6.7, and 3.6.8 are all part of the Python 3.6 minor version.
• MICRO - Typically, the new micro versions contain various bug fixes and
improvements.
Hello world Python Program
Print(“Hello Program”);
Python Editors and Installation
• A Python identifier is a name used to identify a variable, function, class, module or other object.
• An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more
letters, underscores and digits (0 to 9).
• Python does not allow punctuation characters such as @, $, and % within identifiers.
• Python is a case sensitive programming language.
• Thus, Manpower and manpower are two different identifiers in Python.
Python Identifiers
Here are naming conventions for Python identifiers −
• Class names start with an uppercase letter. All other identifiers start with a lowercase letter.
• Starting an identifier with a single leading underscore indicates that the identifier is private.
• Starting an identifier with two leading underscores indicates a strongly private identifier.
• If the identifier also ends with two trailing underscores, the identifier is a language-defined special
name.
Python Reserved Words (Keywords)
and exec not
assert finally or
break for pass
class from print
continue global raise
def if return
del import try
elif in while
else is with
except lambda yield
Lines and Indentation
Python provides no braces to indicate blocks of code for class and function definitions or flow control.
Blocks of code are denoted by line indentation, which is rigidly enforced.
The number of spaces in the indentation is variable, but all statements within the block must be
indented the same amount.
For example −
if True:
print "True"
else:
print "False"
Multi-Line Statements
• Statements in Python typically end with a new line. It allow the use of the line continuation
character (\) to denote that the line should continue.
For example −
total = item_one + \
item_two + \
item_three
Quotation in Python
Python accepts single ('), double (") and triple (''' or """) quotes to denote string literals, as long
as the same type of quote starts and ends the string.
word = 'word'
sentence = "This is a sentence."
paragraph = """This is a paragraph. It is
made up of multiple lines and sentences."""
Comments
• A hash sign (#) that is not inside a string literal begins a comment.
• All characters after the # and up to the end of the physical line are part of the comment and the
Python interpreter ignores them.
#!/usr/bin/python
# First comment
print "Hello, Python!" # second comment
Multiple lines
• The semicolon ( ; ) allows multiple statements on the single line given that neither statement
starts a new code block.
• import sys; x = 'foo'; sys.stdout.write(x + '\n')
and Logical AND If both the operands are true (a and b) is true.
then condition becomes true.
not Logical NOT Used to reverse the logical state Not(a and b) is false.
of its operand.
Python Membership Operators
Python’s membership operators test for membership in a sequence, such as strings, lists, or
tuples.