Don't understand this python function

In summary, a python function is a block of reusable code that takes in input parameters, processes them, and returns a result. To define a function, you use the "def" keyword, followed by the function name and a set of parentheses containing parameters. To call a function, you write the function name followed by parentheses with arguments. The difference between parameters and arguments is that parameters are defined in the function header, while arguments are provided when calling the function. It is possible to return multiple values from a function by separating them with commas and using the "return" keyword, which will return a tuple that can be unpacked or accessed using indexing.
  • #1
zeion
466
1

Homework Statement



Hi,

I'm not sure what this does:

s = 'hello'

I understand

s[::-1] would reverse the order of the letters and
s[1::] slices the first letter

but how come

s[1::-1] returns 'eh' ?


Homework Equations





The Attempt at a Solution

 
Technology news on Phys.org

Related to Don't understand this python function

1. What is a python function and how does it work?

A python function is a block of reusable code that is designed to perform a specific task. It takes in input parameters, processes them, and returns a result. Functions allow for code reusability and improve the efficiency of a program.

2. How do I define a python function?

To define a python function, you use the "def" keyword, followed by the function name, and a set of parentheses containing any parameters. The function body is then indented below and can contain any valid python code. Finally, you use the "return" keyword to specify the value you want the function to return.

3. How do I call a python function?

To call a python function, you simply write the function name followed by a set of parentheses containing any required arguments. If the function returns a value, you can assign it to a variable or use it directly in your code.

4. What is the difference between a parameter and an argument in a python function?

A parameter is a variable that is used in the function definition to represent the input values. An argument, on the other hand, is the actual value that is passed into the function when it is called. Parameters are defined in the function header, while arguments are provided when calling the function.

5. Can I return multiple values from a python function?

Yes, you can return multiple values from a python function by separating them with commas after the "return" keyword. The values will be returned as a tuple, which can then be unpacked or accessed using indexing.

Similar threads

  • Programming and Computer Science
2
Replies
55
Views
4K
  • Programming and Computer Science
Replies
1
Views
774
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
34
Views
3K
  • Programming and Computer Science
Replies
9
Views
2K
  • Programming and Computer Science
Replies
11
Views
910
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
3
Views
526
  • Programming and Computer Science
Replies
16
Views
1K
  • Programming and Computer Science
Replies
3
Views
2K
Back
Top