PWP UNIT 1 Notes
PWP UNIT 1 Notes
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
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/
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 Identifiers Variable name is known as identifier. A variable is nothing but a reserved
memory location to store values.
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
Programming with Python(22616)
Print is a statement'''
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
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")
A data type defines the type of data, for example 123 is an integer data while “hello” is a String
type of data.
Data Types
Mutable Immutable
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
(,).
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.
Programming with Python(22616)
Assignment Questions :