0% found this document useful (0 votes)
2 views24 pages

2-introduction to Python programming Lang

The document provides an introduction to Python, highlighting its features as a high-level, interpreted, and object-oriented programming language that is beginner-friendly and easy to read and maintain. It covers essential concepts such as identifiers, variables, reserved words, and the importance of indentation in Python syntax. Additionally, it includes instructions for downloading and installing Python, as well as a brief overview of its capabilities and interactive programming environment.

Uploaded by

newfrost7
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views24 pages

2-introduction to Python programming Lang

The document provides an introduction to Python, highlighting its features as a high-level, interpreted, and object-oriented programming language that is beginner-friendly and easy to read and maintain. It covers essential concepts such as identifiers, variables, reserved words, and the importance of indentation in Python syntax. Additionally, it includes instructions for downloading and installing Python, as well as a brief overview of its capabilities and interactive programming environment.

Uploaded by

newfrost7
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Introduction to Programming with Python

1
Introduction to Python
• Python is a high-level programming language
• Open source and community driven
• “Batteries Included”
• a standard distribution includes many modules
• Dynamic typed
• Source can be compiled or run just-in-time
• Similar to perl, tcl, ruby
Features of Python
Python is a high-level, interpreted, interactive and object
oriented-scripting language. Python was designed to be highly
readable which uses English keywords frequently where as
other languages use punctuation and it has fewer syntactical
constructions than other languages.
• Python is Interpreted: This means that it is processed at runtime
by the interpreter and you do not need to compile your program
before executing it. This is similar to PERL and PHP.
• Python is Interactive: This means that you can actually sit at a
Python prompt and interact with the interpreter directly to write
your programs.
• Python is Object-Oriented: This means that Python supports
Object-Oriented style or technique of programming that
encapsulates code within objects.
• Python is Beginner's Language: Python is a great language for the
beginner programmers and supports the development of a wide
range of applications, from simple text processing to WWW
browsers to games.
• Python's feature highlights include:
• Easy-to-learn: Python has relatively few keywords, simple structure, and a clearly
defined syntax. This allows the student to pick up the language in a relatively short
period of time.
• Easy-to-read: Python code is much more clearly defined and visible to the eyes.
• Easy-to-maintain: Python's success is that its source code is fairly easy-to-maintain.
• A broad standard library: One of Python's greatest strengths is the bulk of the
library is very portable and cross-platform compatible on UNIX, Windows, and
Macintosh.
• Interactive Mode: Support for an interactive mode in which you can enter results
from a terminal right to the language, allowing interactive testing and debugging of
snippets of code.
• 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.
Apart from the above mentioned features, Python has a big list of good features,
few are listed below:
• Support for 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.
• Very high-level dynamic data types and supports dynamic type checking.
• Supports automatic garbage collection.
• It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.

By the way, the language is named after the BBC show “Monty Python’s Flying
Circus” and has nothing to do with nasty reptiles. Making references to Monty
Python skits in documentation is not only allowed, it is encouraged!
Python 3 is available for Windows, Mac OS and most of the flavors of Linux
operating system. Even though Python 2 is available for many other OSs, Python
3 support either has not been made available for them or has been dropped.
Exercise 1:
• DOWNLOAD PYTHON INTERPRETER
• Installing Python Programming Language

Getting Python on Windows platform: 

Binaries of latest version of Python 3 are available on Python Official Website.

For versions 3.0 to 3.4.x, Windows XP is acceptable. In order to install Python 3.5 to 3.8- minimum OS
requirements are Windows 7 with SP1. Python 3.9+ cannot be used on Windows 7 or earlier. 

Python 3.13 is the newest major release of the Python programming language:

The most up-to-date and current source code, binaries, documentation, news, etc., is available on the official
website of Python. You can download Python documentation from the site. The documentationis available
in HTML, PDF and PostScript formats.

Python Official Website: [Link] Official Website: [Link]
• You can create and run python codes on your mobile devices. There are so many python 3 interpreter and
IDE available on Google and IOS play store. For example, Pydroid 3 on Android phone. Pyto on IOS/ipad
• -Understand the following:
i. Local Environment Setup
ii. Running Python
First Python Program
•Interactive Mode Programming
Invoking the interpreter without passing a script file as a parameter brings up
the following prompt-

Type the following text at the Python prompt and press Enter-
Program Elements
• Identifiers:
• Variables:
• Reserved words

8
Python 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).
• Must begin with letter or underscore, followed by any
number of letters, digits, underscores

9
Rules for writing identifiers
• Identifiers can be a combination of letters in lowercase (a to z) or uppercase
(A to Z) or digits (0 to 9) or an underscore _.
Valid examples: Names like myClass, var_1 and print_this_to_screen,

• An identifier cannot start with a digit.


1variable is invalid, but variable1 is perfectly fine.
• Keywords cannot be used as identifiers.
>>> global = 1
File "<interactive input>", line 1
global = 1
^
SyntaxError: invalid syntax
10
Rules for writing identifiers
• We cannot use special symbols like !, @, #, $, % etc. in
our identifier.
>>> a@ = 0
File "<interactive input>", line 1
a@ = 0
^
SyntaxError: invalid syntax

• Identifier can be of any length.

11
Case-sensitivity
• Python is a case-sensitive language. This means, Variable
and variable are not the same.
• Thus, Manpower and manpower are two different
identifiers in Python.

12
Variables
• Variables:
–Do not need to be declared
–A variable is created when a value is assigned to it: 
Examples: num = 3
–Can’t be used in an expression unless it has a
value
–Error message: Name Error – means no value is
associated with this name

13
Variables
• In many programming languages, variables
are statically typed. That means a variable is >>> var = 23.5
initially declared to have a specific data type, >>> print(var)
and any value assigned to it during its 23.5
lifetime must always have that type.
>>> var = "Now I'm a string"
>>> print(var)
• Variables in Python are not subject to this Now I'm a string
restriction. In Python, a variable may be
assigned a value of one type and then later
re-assigned a value of a different type:
• Variable names don’t have static types – values (or objects) do
A variable name has the type of the value it currently references
14
Variables contain references to data values
Variables actually contain
3.5
references to values (similar A A=A*2 A 3.5
to pointers). A = “cat”
This makes it possible to 7.0
assign different object types
to the same variable
“cat”

• Python handles memory management automatically. It will create new objects


and store them in memory; it will also execute garbage collection algorithms to
reclaim any inaccessible memory locations.
• Python does not implement reference semantics for simple variables; if A = 10
and B = A, A = A + 1 does not change the value of B

15
Reserved Words
The following list shows the Python keywords. These are reserved
words and you cannot use them as constants or variables or any
other identifier names. All the Python keywords contain lowercase
letters only.

16
Reserved words

17
Lines and Indentation
• Python does not use 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-

Thus, in Python all the continuous lines indented with the same number of spaces would 18
form a block.
Multi-Line Statements
• Statements in Python typically end with a new line.
Python, however, allows the use of the line continuation
character (\) to denote that the line should continue. For
example

• The statements contained within the [], {}, or () brackets


do not need to use the line continuation character. For
example

19
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.
• The triple quotes are used to span the string across
multiple lines. For example, all the following are legal

20
Comments in Python
• A hash sign (#) that is not inside a string literal is the
beginning of a comment. All characters after the #, up to
the end of the physical line, are part of the comment and
the
• Python interpreter ignores them.

21
• You can type a comment on the same line after a
statement or expression

• Python does not have multiple-line commenting feature.


You have to comment each line individually as follows-

22
Using Blank Lines

• A line containing only whitespace, possibly with a


comment, is known as a blank line and Python totally
ignores it.
• In an interactive interpreter session, you must enter an
empty physical line to terminate a multiline statement.

23
Interesting Features
• White space does indicate meaning
–Instead of curly brackets or begin-end pairs,
whitespace is used for block delimiters.
–Indent statements in a block, un-indent at end of
block.
• Statements are terminated by <Enter>
• No variable declarations
• Dynamic typing

24

You might also like