Вы находитесь на странице: 1из 4

National Institute of Engineering, Mysuru

Department of Electronics and Communication Engineering


INTERNET OF THINGS LAB-2
Introduction to Python Programming

Python is a high-level, interpreted, interactive and object-oriented scripting language. It was


created by Guido van Rossum in the late eighties and early nineties at the National Research
Institute for Mathematics and Computer Science in the Netherlands.

Features of Python:

1. Supports functional and structured programming methods as OOP.


2. Provides high-level dynamic data types and supports dynamic checking.
3. Easily integrated with C, C++, COM, Active X, COBRA and JAVA.
4. A board standard library, Interactive mode, Portable, Extendable.

Other features:

1. Python is a fully-functional programming language that can do anything almost any other
language can do, at comparable speeds.
2. Modules are actually just Python wrappers around C/C++ code. "Modules" are pre-written
Python code that you "import" in your Python program.
3. Python can be used to make games, do data analysis, control robot and hardware,
create GUIs, or even to create websites.

Python Data types:

1. Numbers: they store numeric values. Number objects are created when a value is
assigned to them.

Department of Electronics and Communication Page 1


Example: var1 = 05, var2 = 07, a = 10
 Int eg. 18
 Long eg. 0Xabcde12345
 Float eg. 19.89
 Complex eg. 3.75j
2. Strings: Strings in Python are identified as a contiguous set of characters represented in
the quotation marks.
Example: str = 'Hello NIE!'
3. Built in functions: The Python interpreter supports many functions that are built-in
68 as of Python 3.6
 Math
 Type Conversion
 Iterables and Iterators
 Composite data types
 Classes attributes and inheritance
 Input/output
 Variable, references and scope

Configure Python: (Windows)

Download python from https://www.python.org/ as on 04/09/2018 python 3.7.0 is the


latest release. Figure 2.2 shows the installation progress on windows.

Figure 2.2 Python installation setup


Department of Electronics and Communication Page 2
Python shell is shown in Figure 2.3

Figure 2.3 Python shell

To create a New file and to start programming select: File---- New File in the Integrated
DeveLopment Environment (IDLE) of python shown in Figure 2.4

Figure 2.4 New file to write a program

Department of Electronics and Communication Page 3


Python program to add two numbers.

n1 = 7.5
n2 = 3.9
# Add two numbers
sum = float(n1) + float(n2)
# Display the sum
print('The sum of {0} and {1} is {2}'.format(n1, n2, sum))

To run the codes go to Run and select Run module of F5 key. The output of the program
appears in Python shell shown in Figure 2.5

Figure 2.5 Addition of two numbers.

Department of Electronics and Communication Page 4

Вам также может понравиться