ariel20
ariel20

Reputation: 15

Python : using function

how I can make function in program like IDLE or linux terminal? and how I can use loop? when I am trying to use it that happen:

>>>for i in numbers:  # when i am push enter its make ... 
...    print packet[i]  # when i am pushing on the enter its create new line 

Upvotes: 0

Views: 31

Answers (1)

srowland
srowland

Reputation: 1705

A function is defined like this:

def my_func(arg_one):
    return arg_one * 2

print my_func(2)

4

I thoroughly recommend the Python tutorial here as a great place to get started learning Python.

And you can simulate a loop in your interpreter like this:

>>> for i in range(5): # press enter
...    print i         # press enter again
...                    # press enter again
...
0
1
2
3
4
>>>

Note the use of # which is the proper way to start a line comment in Python too.

Upvotes: 1

Related Questions