Unit 1 Python
Unit 1 Python
Syllabus
The implementation of Python was started in December 1989 by Guido Van Rossum at CWI in the Netherlands.
In February 1991, van Rossum published the code (labeled version 0.9.0) to alt.sources.
1994, Python 1.0 was released with new features like lambda, map, filter, and reduce.
Python 2.0 added new features like a list comprehension & garbage collection system.
On December 3, 2008, Python 3.0 (also called “Py3K”) was released. It was designed to rectify fundamental flaw of the language.
What can Python do?
Python can connect to database systems. It can also read and modify files.
Python can be used to handle big data and perform complex mathematics.
Python has syntax that allows developers to write programs with fewer lines than
some other programming languages.
Python Syntax compared to other programming languages
Python was designed for readability, and has some similarities to the English language
with influence from mathematics.
2) Expressive Language : Python can perform complex tasks using a few lines of code. A simple example, the hello
world program you simply type print("Hello World"). It will take only one line to execute, while Java or C takes
multiple lines.
3) Interpreted Language : Python is an interpreted language; it means the Python program is executed one line at a
time. The advantage of being interpreted language, it makes debugging easy and portable.
4) Cross-platform Language : 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. It enables programmers to develop the software for
several competing platforms by writing a program only once.
Python Features
5) Free and Open Source : Python is freely available for everyone. It is freely available on its official website
www.python.org. It has a large community across the world that is dedicatedly working towards make new python
modules and functions. Anyone can contribute to the Python community. The open-source means, "Anyone can
download its source code without paying any penny."
6) Object-Oriented Language : Python supports object-oriented language and concepts of classes and objects come into
existence. It supports inheritance, polymorphism, and encapsulation, etc. The object-oriented procedure helps to
programmer to write reusable code and develop applications in less code.
7) Large Standard Library : It provides a vast range of libraries for the various fields such as machine learning, web
developer, and also for the scripting. There are various machine learning libraries, such as Tensor flow, Pandas, Numpy,
Keras, and Pytorch, etc. Django, flask, pyramids are the popular framework for Python web development.
Python Applications
Python Input Function
Python input() function is used to get input from the user. It prompts for the user input
and reads a line. After reading data, it converts it into a string and returns that. It throws
an error EOF Error if EOF is read.
Python input() Function Example 1
Here, we are using this function get user input and display to the user as well.
# Python input() function example
# Calling function
val = input("Enter a value: ")
# Displaying result
print("You entered:",val)
Output:
Enter a value: 45
You entered: 45
Python print() Function
Python print() function prints the given object on the screen or other
standard output devices.
Example:
One of the key features in Python is "Typecasting". Typecasting in Python allows programmers to convert variables or
data from one data type to another. It enables smooth manipulation of data. Typecasting in Python can be very useful in
dealing with large data sets where the data is present in different data types. We can convert mutable datatypes into
immutable ones and vice versa.
Common Typecasting Techniques in Python : Python offers two ways to perform typecasting.
• Implicit typecasting
• Explicit typecasting
• 1. Implicit Typecasting in Python : Implicit typecasting is performed automatically by the interpreter, without user
intervention. Python automatically converts one data type to another data type. This process doesn’t need any user
involvement Python promotes the conversion of lower data type, for example, integer to higher data type says float
to avoid data loss. This type of conversion or type casting is called UpCasting.
Example of Implicit Typecasting in Python
# Python Automatically converts
# a to int
a=7
Print (type(a))
In this method, Python needs user involvement to convert the variable data type into the required data
type.
# initializing integer
s = '4'
c = ord(s)
print (c)
c = hex(56)
print (c)
c = oct(56)
print (c)
Output