Blogger Themes

Search This Blog

www.embeddedstudy.com | Copyright © 2017 | All Rights Reserved | Nithin Pradeep . Theme images by Storman. Powered by Blogger.

Follow by Email

Popular KOZHI

Sponsor

Download

Blogger Tricks

FEATURED

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...

JOIN THE TEAM

Popular Posts

Wikipedia

Search results

Search This Blog

Social

More Links

Social

ad

ads

Friday, 25 August 2017

Creating Modules in Python


In this section we will discuss how to create module in Python...

what is a module?

module is a Python object with arbitrarily named attributes that you can bind and reference. Simply, a module is a file consisting of Python code. A module can define functions, classes and variables. A module can also include runnable code.

See the following program

We are creating 2 modules one for (cal_c.py)arithmetic operations like add,subtract,... and other for finding power(math_c.py).


math_c.py

cal_c.py

project.py
The program will prints output as
 30
25
27
10

in shell....




A pyc file is created after impporting..
We have to create .pyc file for security purposes since in python application it self is cource code.It is automatically created for modules and packages but not for normal files,
else we can create like this.
python -m py_compile p2.py
this p2.pyc is called as byte code or frozen binary.





LIST 

 l.reverse(l.sort) - will print list in reverse order
 l.append(subl)
>>> l
[1, 2, 3, 60, 4, 5, 6, 500, [100, 200, 300]]

this will append whole list

>>> l.extend(subl)
>>> l
[1, 2, 3, 60, 4, 5, 6, 500, [100, 200, 300], 100, 200, 300]

 
this will append only list elements as individual,ie it needs itrative items

l.append(123) works but l.extend(123) will give error.
 l.pop() will pop data from list and will give return value also.

 l.remove(3)- removes first occurance of 3.
lets see..
ASSIGNMENT
Write a program to delete all occurance of given number from list.


l1=l implies that l1 is reference to l.
del command will delete a perticular member .

  • how to print a perticular character from a list.to print 't' and [20,30] from [10,'Nithin',20,[10,20,30]]  


in the next section we will discuss about list comprehension...

<<previous                                                                                                                                Next>>

0 on: "Creating Modules in Python"