Python Programming (Unit-1)
Python Programming (Unit-1)
TECHNOLOGY, BANDA
“PYTHON PROGRAMMING”
BCC-402
UNIT – I
Compiled by
Abhishek Tiwari
(Assistant Professor)
INTRODUCTION
The programming language Python was conceived in the late 1980s, and its implementation
was started in December 1989 by Guido van Rossum at CWI in the Netherlands as a
successor to ABC capable of exception handling and interfacing with the Amoeba operating
system. Van Rossum is Python's principal author, and his continuing central role in deciding
the direction of Python is reflected in the title given to him by the Python community,
Benevolent Dictator for Life (BDFL). (However, Van Rossum stepped down as leader on July
12, 2018). Python was named after the BBC TV show Monty Python's Flying Circus.
Python is a widely used general-purpose, high level programming language. 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. Python is a programming language that lets you work
quickly and integrate systems more efficiently.
There are two major Python versions- Python 2 and Python 3.
On 16 October 2000, Python 2.0 was released with many new features.
On 3rd December 2008, Python 3.0 was released with more testing and includes new
features.
As of April 8, 2025, the latest Python 3 release is Python 3.13.2
PYTHON TOKENS
In python tokens are small individual unit that are used to create or write program instructions.
Python provides multiple types of tokens:
Keywords
Identifiers
Literals
Operators
Punctuations
Keywords: Keywords are reserved words whose meaning is fixed and will never change.
For example –
a = 100 # An integer assignment
b = 1000.0 # A floating point
c = "John" # A string
print (a)
print (b)
print (c)
This produces the following result –
100
1000.0
John
Multiple Assignment: Python allows you to assign a single value to several variables
simultaneously.
For example:
a=b=c=1
Here, an integer object is created with the value 1, and all three variables are assigned to the
same memory location.
You can also assign multiple objects to multiple variables.
For example –
a,b,c = 1,2,"mrcet“
Here, two integer objects with values 1 and 2 are assigned to variables a and b respectively,
and one string object with the value "john" is assigned to the variable c.
Output Variables:
The Python print statement is often used to output variables. Variables do not need to be
declared with any particular type and can even change type after they have been set.
x=5 # x is of type int
x = "mrcet " # x is now of type str
print(x)
Output: mrcet
To combine both text and a variable, Python uses the “+” character:
Example:
x = "awesome"
print("Python is " + x)
Output: Python is awesome
You can also use the + character to add a variable to another variable:
Example:
x = "Python is "
y = "awesome"
z=x+y
print(z)
Output: Python is awesome
Arithmetic operators
Assignment operators
Comparison operators
Logical operators
Identity operators
Membership operators
Bitwise operators
Arithmetic operators
Assignment operators
Operator Example Same As
= x=5 x=5
+= x += 3 x=x+3
-= x -= 3 x=x-3
*= x *= 3 x=x*3
/= x /= 3 x=x/3
%= x %= 3 x=x%3
//= x //= 3 x = x // 3
**= x **= 3 x = x ** 3
&= x &= 3 x=x&3
|= x |= 3 x=x|3
^= x ^= 3 x=x^3
>>= x >>= 3 x = x >> 3
<<= x <<= 3 x = x << 3
Logical operators
Not Reverse the result, returns False if the result is not(x < 5 and x < 10)
true
Identity operators
Membership operators
Operator Description Example
in Returns True if a sequence with the specified value x in y
is present in the object
not in Returns True if a sequence with the specified value x not in y
is not present in the object
Bitwise operators
int:
int, or integer, is a whole number, positive or negative, without decimals, of unlimited
length.
>>> print(24656354687654+2)
24656354687656
>>> print(20)
20
>>> print(0b10)
2
>>> print(0B10)
2
>>> print(0X20)
32
>>> 20
20
>>> 0b10
2
>>> a=10
>>> print(a)
10
# To verify the type of any object in Python, use the type() function:
>>> type(10)
>>> a=11
>>> print(type(a))
<class ‘int‘>
float:
float, or "floating point number" is a number, positive or negative, containing one or
more decimals. float can also be scientific numbers with an "e" to indicate the power of 10.
>>> y=2.8
>>> y
2.8
>>> y=2.8
>>> print(type(y))
<class ‘float’>
>>> type(.4)
<class ‘float’>
>>> 2.
2.0
Example:
x = 35e3
y = 12E4
z = -87.7e100
print(type(x))
print(type(y))
print(type(z))
Output:
<class ‘float’>
<class ‘float’>
<class ‘float’>
Boolean:
Objects of Boolean type may have one of two values, True or False:
>>> type(True)
>>> type(False)
String:
Strings in Python are identified as a contiguous set of characters represented in the
quotation marks. Python allows for either pairs of single or double quotes.
'hello' is the same as "hello".
Strings can be output to screen using the print function.
For example:
print("hello")
>>> print("mrcet college")
mrcet college
>>> type("mrcet college")
<class ‘str’>
>>> print('mrcet college')
mrcet college
>>> " "
''
If you want to include either type of quote character within the string, the simplest way is to
delimit the string with the other type. If a string is to contain a single quote, delimit it with
double quotes and vice versa:
>>> print("mrcet is an autonomous (') college")
mrcet is an autonomous (') college
>>> print('mrcet is an autonomous (") college')
mrcet is an autonomous (") college
Specifying a backslash (\) in front of the quote character in a string “escapes” it and
causes Python to suppress its usual special meaning. It is then interpreted simply as a literal
single quote character:
The following is a table of escape sequences which cause Python to suppress the usual
special interpretation of a character in a string:
>>> print('a\ ....b')
a....b
>>> print('a\
b\
c')
abc
>>> print('a \n b')
a
b
>>> print("mrcet \n college")
mrcet
college