Blogger Themes

Search This Blog | Copyright © 2017 | All Rights Reserved | Nithin Pradeep . Theme images by Storman. Powered by Blogger.

Follow by Email

Popular KOZHI



Blogger Tricks


What is an Embedded System?

An embedded system is a combination of hardware and software that is designed to carry out a certain task or tasks, meaning it has a s...


Popular Posts


Search results

Search This Blog


More Links




Monday, 21 August 2017

Modules in Python

In this section we will discuss about ,lambda function and modules in Python.

Lambda Function

Lambda is an anonymous function,this function needs expressions and returns an object ,this function is not going to be created in standard way.

The above program will print 30 and 25.

Modules in Python

A Python module is simply a Python source file, which can expose classes, functions and global variables. When imported from another Python source file, the file name is treated as a namespace. A Python package is simply a directory of Python module(s).
keyword is a module it shows how many keywords and related informations.
dir(keyword) wont work unless we import keyword.
so to import type ..

['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']
these are the available keywords in the Python,they are 31 of them.
Now let us see calendar and time modules.
import calendar as cal   - we can use cal instead of calendar module.

print cal.monthrange(2017,10)
will give (6, 31)
here 6 indicates it is sunday(0-mon,1-tue,2-wed......6-sun) and 31 ,the no of days in the month.
Now let us see time function..
time.time() -will give epoch time ie from 1970 jan 1.
time.localtime(time.time()) - will give time in structure format.
time.asctime(time.localtime(time.time())) -access time will give time in string format.

String based functions in Python

Let us see some examples of string functions..

s.strip() removes blank spaces from both ends while s.split() will split spaces and make in to list.
s.index('i') gives the first position of 'i'.
 s.index('deep') gives the starting position of d

if substring not found then it will print not found.


The platform module in Python is used to access the underlying platform's data, such as, hardware, operating system, and interpreter version information. The platform module includes tools to see the platform's hardware, operating system, and interpreter version information where the program is running.
 import platform
>>> platform.python_version()   - will give current python version

>>> platform.version() - will give platform.

>>> from platform import * -can import a particular platform

>>> from platform import python_version -import only python_version and nothing else
In the next section we will discuss about creation of our own modules and list functions...
<<Previous                                                                                                                                                              Next>>

0 on: "Modules in Python"