0% found this document useful (0 votes)
127 views7 pages

PWP Unit 1

The document discusses the introduction and syntax of the Python programming language. It covers Python features, building blocks like identifiers and variables, data types, and provides examples of simple Python scripts. The key topics covered are Python installation, running simple scripts, data types like numbers, strings, lists, tuples and dictionaries.

Uploaded by

viraj babar
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)
127 views7 pages

PWP Unit 1

The document discusses the introduction and syntax of the Python programming language. It covers Python features, building blocks like identifiers and variables, data types, and provides examples of simple Python scripts. The key topics covered are Python installation, running simple scripts, data types like numbers, strings, lists, tuples and dictionaries.

Uploaded by

viraj babar
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
You are on page 1/ 7

Programming with Python(22616)

UNIT I : Introduction and Syntax of Python Program

Contents :
1.1 Features of Python - Interactive, Object -oriented, Interpreted, platform independent
1.2 Python building blocks - Identifiers, Keywords, Indention, Variables, Comments
1.3 Python environment setup - Installation and working of IDE.
1.4 Running Simple Python scripts to display 'welcome' message.
1.5 Python Data Types: Numbers, String, Tuples, Lists, Dictionary. Declaration and use of data types
______________________________________________________________________________________

Course Outcome : Display message on screen using Python script on IDE.


______________________________________________________________________________________

References :

1. https://www.tutorialspoint.com/index.htm
2. nptel.ac.in/courses/117106113/34
3. https://www.w3schools.com/python/default.asp
4. https://www.programiz.com/python-programming
5. https://docs.python.org/3/tutorial/errors.html
6. https://www.w3resource.com/python-exercises/

Mrs.Kajal.G.Raut
Programming with Python(22616)

 Features of python –

1. Python is Interactive – You can actually sit at a Python prompt and interact with the
interpreter directly to write your programs.
2. Python is Object-Oriented Language – Python supports object oriented language and
concepts of classes and objects come into existence.
3. Python is 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.
4. Python is Platform Independent - Python can run equally on different platforms such
as Windows, Linux, Unix and Macintosh etc. So, we can say that Python is a portable
language.
5. It is high level programming language.
6. Python is free and open source programming language.
7. Python is Dynamic Language.

 Python Building Blocks:

1. Python Identifiers and Variable :

Python Identifiers Variable name is known as identifier. A variable is nothing but a reserved
memory location to store values.

The rules to name an identifier are given below:

- The first character of the variable must be an alphabet or underscore ( _).


- All the characters except the first character may be an alphabet of lower-case(a-z),
upper-case (A-Z), underscore or digit (0-9).
- Identifier name must not contain any white-space, or special character (!, @, #, %, ^,
&, *).
- Identifier name must not be similar to any keyword defined in the language.
- Identifier names are case sensitive.
- for example myname, and MyName is not the same.
- Examples of valid identifiers : a123, _n, n_9, etc.
- Examples of invalid identifiers: 1a, n%4, n 9, etc.

Mrs.Kajal.G.Raut
Programming with Python(22616)

2. Keywords :

The name of keywords cannot be used as variable name. For instance a variable
name cannot be from because it is a keyword.

3. 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
compulsory.
- White space at the beginning of the logical line is called indentation.
- For example :
a= 1;
if a<=2; here the line is indented that means this statement will
print (‘True’) execute only if the if statement is true.

4. Comments :

- Single Comment :
• Use the hash (#) symbol to start writing a comment.
• E.g #This is a comment
print('Hello')

- Multiple Comment :
• In some situations, multiline documentation is required for a program. If we have
comments that extend multiple lines, one way of doing it is to use hash (#) in the
beginning of each line. Another way of doing this is to use quotation marks, either
''' or """.
• Similarly, when it sees the triple quotation marks ''' it scans for the next ''' and ignores

Mrs.Kajal.G.Raut
Programming with Python(22616)

any text in between the triple quotation marks.

Example: For multiline comment.

'''This is first python program

Print is a statement'''

 Modes of working in Python :


Python has two basic modes: script and interactive.

1. Interactive mode is a command line shell which gives immediate feedback for each
statement, while running previously fed statements in active memory.

2. Script mode is also called as normal mode. This is mode in which the python
commanda are stores in file and the file is saved using the extension .py

 Running Simple Python scripts to display 'welcome' message.

Here we will be using the Python print() function for the same. The print() function in Python is
used to print Python objects as strings as standard output.

Example:
# python program to print "Hello World"
print("Hello World")

 Python Data Types:

A data type defines the type of data, for example 123 is an integer data while “hello” is a String
type of data.

The data types in Python are divided in two categories:

Data Types

Mutable Immutable

List Dictionary Set Numeric Strings Tuples

Mrs.Kajal.G.Raut
Programming with Python(22616)

Mutable date types are those, whose value can be change after creation. List, Sets, and
Dictionary in Python are examples of some mutable data types in Python.

Immutable data types are those, whose values cannot be modified once they are created.
Examples of immutable data types are int, str, bool, float, tuple, etc.

1. Numeric :
Python numeric data type is used to hold numeric values like,
 int – holds signed integers of non-limited length.
 long- holds long integers(exists in Python 2.x, deprecated in Python 3.x).
 float- holds floating precision numbers and it’s accurate upto 15 decimal places.
 complex- holds complex numbers.

2. String
The string is a sequence of characters. Python supports Unicode characters. Generally,
strings are represented by either single or double quotes.

3. List
List is an ordered sequence of some data written using square brackets ([]) and commas
(,).

Mrs.Kajal.G.Raut
Programming with Python(22616)

4. Tuple
Tuple is another data type which is a sequence of data similar to list. But it is immutable.
That means data in a tuple is write protected. Data in a tuple is written using parenthesis
and commas.

5. Dictionary
Python Dictionary is an unordered sequence of data of key-value pair form. It is similar
to the hash table type. Dictionaries are written within curly braces in the form key: value.

Mrs.Kajal.G.Raut
Programming with Python(22616)

Assignment Questions :

1. Enlist different features of python.


2. List and define modes in Python.
3. Describe Python Building Blocks.
4. List and Explain different data types used in Python.
5. What are the rules to be followed for variable names.
6. Write a Python Program to display welcome message.

Mrs.Kajal.G.Raut

You might also like