Unit 1 Introduction and Syntax of Python Programming 1
Unit 1 Introduction and Syntax of Python Programming 1
Python is developed by Guido van Rossum. Guido van Rossum started implementing
Python in 1989.
Features of python –
Python is Interactive –
You can actually sit at a Python prompt and interact with the interpreter directly to
write your programs.
Python is Object-Oriented –
Python supports object oriented language and concepts of classes and objects come into
existence.
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.
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.
Course Outcome (CO): Display message on screen using Python Script on IDE.
Python Identifiers
Eg: x=y=z=50
Eg: a,b,c=5,10,15
Reserved Words
The following list shows the Python keywords. These are reserved words and cannot use
them as constant or variable or any other identifier names. All the Python keywords
contain lowercase letters only.
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.
The number of spaces in the indentation is variable, but all statements within the block
must be indented the same amount. For example −
if True:
print "True"
else:
print "False"
Thus, in Python all the continuous lines indented with same number of spaces would form
a block.
Course Outcome (CO): Display message on screen using Python Script on IDE.
Variable Types
Variables are used to store data, they take memory space based on the type of value we
assigning to them. Creating variables in Python is simple, you just have write the variable
name on the left side of = and the value on the right side.
num = 100
str = "BeginnersBook"
print(num)
print(str)
x = y = z = 99
print(x)
print(y)
print(z)
a, b, c = 5, 6, 7
print(a)
print(b)
print(c)
x = 10
y = 20
print(x + y)
p = "Hello"
q = "World"
print(p + " " + q)
Course Outcome (CO): Display message on screen using Python Script on IDE.
output:
30
Hello World
Comments
Multi-line comments
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:
1. Immutable data types – Values cannot be changed.
2. Mutable data types – Values can be changed
Install Python on any operating system such as Windows, Mac OS X, Linux/Unix and others.
1. On Windows 7 and earlier, IDLE is easy to start—it‘s always present after a Python
install, and has an entry in the Start button menu for Python in Windows 7 and earlier.
2. Select it by right-clicking on a Python program icon, and launch it by clicking on the icon
for the files idle.pyw or idle.py located in the idlelib subdirectory of Python‘s Lib directory.
In this mode, IDLE is a clickable Python script that lives in C:\Python3.6\..
List is an ordered sequence of some data written using square brackets ([]) and commas (,).
Course Outcome (CO): Display message on screen using Python Script on IDE.
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.
Course Outcome (CO): Display message on screen using Python Script on IDE.
Dictionary