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.
Versions of Python
1) Python 1.0 Jan 1994
2) Python 1.5 31 Dec 1997
3) Python 1.6 5 Sept 2000
4) Python 2.0 16 Oct 2000
5) Python 2.7 3 July 2010
6) Python 3.0 3 Dec 2008
7) Python 3.8 14 Oct 2019
Features of Python
1)Interactive
2) Object Oriented
3) Interpreted
4) Platform independent
Interactive
• You can actually sit at a Python prompt and
interact with the interpreter directly to write
your programs.
Object Oriented
• Python supports Object-Oriented style or
technique of programming that encapsulates
code within 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.
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