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

Saturday, 19 August 2017

Functions in Python



Before we begin functions let us discuss some important points. . .


Type conversion


  
x=1000
str(x) 

will give '1000' so the value cannot be changed because string is immutable in python

similarly see some type conversions below..

while using cmp(x,y) if it returns non zero indicates that strings/list/tuple are not equal.

 

FUNCTIONS

Functions can be created in two ways:

def() -Regular standard function
lambda() -anonymous function no function name.

import can be used to import file from terminal to python prompt

lets see a program...
the above program will print
in function
Hello World
test() will take zero arguments and return NULL 

dir(str) -will give directory
help(str.index) -will give man page

The arguments can be called in a function using:
  1. Required arguments(The number of called function and calling function should be same)
  1. Keyword arguments
  1. Default arguments  (add(x,y)  or  add(y,x))
  1. Variable arguments


the program will print  :
hello in function 10 20
value=30

Keyword arguments
Required arguments

 Default argument 
In the above program default marks will be taken if it is not provided in function call.


Variable argument
In Python return function can return more than one function which C language cannot perform.The values are returned in tuple format.

to use global variable inside a block use global keyword

 OUTPUT :               
  While using any kind of functions value is called as call by reference.
 

Thats all for this section,In the next section we will discuss modules in Python...

<<Previous                                                                                                                          Next>> 

0 on: "Functions in Python"