0

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 
2
  • you just need to press enter again to execute your for loop - try for i in range(10): print i to give you a flavour. Commented Mar 21, 2016 at 20:50
  • thank you very much, what about functions? Commented Mar 21, 2016 at 20:54

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

if my line is very long how can I continue it in under line?
this is a new question really ... however, you can use the `\` character at the end of a line to carry it onto the next line :)
@ariel20: I second the suggestion to start through the tutorial. All the questions you have asked are explained there. That is how I started 19 years ago.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.