Chapt 1
Chapt 1
Unit outcomes :
1. Identify the given variables , keywords and
constants in python.
2. Use indentation, comments in the given
program.
3. Install the given python IDE and editor.
4. Develop the python program to display the
given text.
Introduction
• Python is a widely used general –purpose, high
level programming language.
• It combines the features of C and Java.
• It was initially designed by Guido van Rossum in
1991 and developed by Python Software
Foundation.
• It was mainly developed for emphasis on code
readability, and its syntax allows programmers
to express concepts in fewer lines of code.
Features of Python
1) Simple and easy to learn
2) Freeware and open source
3) High level programming language
4) Object Oriented
5) Interpreted
6) Platform independent
7) Portability
8) Dynamically Typed
Simple and easy to learn
• Python is a simple programming language.
• When we read Python program,we can feel like
reading english statements.
• The syntaxes are very simple and only 30+
kerywords are available.
• When compared with other languages, we can
write programs with very less number of lines.
Hence more readability and simplicity.
• We can reduce development and cost of the
project.
Freeware and Open Source
• We can use Python software without any
licence and it is freeware.
• Its source code is open, so that we can
customize based on our requirement. Eg:
Jython is customized version of Python to
work with Java Applications.
High level programming language
• Python is high level programming language
and hence it is programmer friendly language.
• Being a programmer we are not required to
concentrate low level activities like memory
management and security etc..
Object Oriented
• Python supports Object-Oriented style or
technique of programming that encapsulates
code within classes and objects.
Interpreted
• Python is an interpreted language i.e. interpreter
executes the code line by line at a time. This makes
debugging easy and thus suitable for beginners.
• Python compiler translates the python program
into an intermediate code called byte code. This
byte code is then executed by PVM.
• Inside PVM an interpreter converts the byte code
instructions into machine code so that processor
will understand and run that machine code to
produce results.
Platform independent
• Like Java programs, Python programs are
also platform independent.
• Once we write a Python program, it can run
on any platform without rewriting once again.
• Python uses PVM to convert python code to
machine understandable code.
Portability
• Python programs are portable. i.e. we can
migrate from one platform to another
platform very easily.
• Python programs will provide same results on
any platform.
Dynamically Typed
• In Python we are not required to declare type for
variables.
• Whenever we are assigning the value, based on
value, type will be allocated automatically.
• Hence Python is considered as dynamically typed
language.
• But Java, C etc are Statically Typed Languages
because we have to provide type at the beginning
only.
• This dynamic typing nature will provide more
flexibility to the programmer.
Python building blocks
1) Identifiers
2) Keywords
3) Indentation
4) Variables
5) Comments
Identifiers
• 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.
• Naming conventions for Python identifiers −
1) Class names start with an uppercase letter. All other identifiers start
with a lowercase letter.
2) Starting an identifier with a single leading underscore indicates that the
identifier is private.
3) Starting an identifier with two leading underscores indicates a strongly
private identifier.
4) If the identifier also ends with two trailing underscores, the identifier is
a language-defined special name.
Keywords
String Literals
• A group of characters is called a string literal.
• They are enclosed in single quotes(‘) or double
quotes(“) or triple quotes (‘’’ or “””).
• Single or double quoted strings should end in the
same line as :
• S1=“This is python prog”
• S2=‘Core Python’
• When a string literal extends beyond a single
line, we should go for triple quotes as follows:
• S1= ‘’’ python has
various features
like object oriented,
interpreted, platform
independent’’’
• s2 = “”” python has
various features
like object oriented,
interpreted, platform independent”””
String Literal
• When a string spans more than one line
adding backslash (\) will join the next string to
it.
• Eg. Str =“ This is first \
chapter of Python \
programming “
Escape Characters in Strings
Escape Meaning
character
\ New Line continuation
\\ display a single \
\b Backspace
\r Enter
\v Vertical tab
\n New line
Determining the datatype of a variable