Hướng dẫn python function without parentheses - hàm python không có dấu ngoặc đơn

Trong Python, có cách nào để gọi một chức năng mà không có dấu ngoặc đơn không?

giống

account.add 3000

Tôi muốn mã hóa một ứng dụng nhanh và sử dụng nó trên cửa sổ Python Shell và tôi nghĩ rằng nó nên tiết kiệm thời gian để nhập các giá trị mà không cần dấu ngoặc đơn đó.

Hướng dẫn python function without parentheses - hàm python không có dấu ngoặc đơn

mkrieger1

Huy hiệu vàng 16K449 Huy hiệu bạc58 Huy hiệu đồng4 gold badges49 silver badges58 bronze badges

Đã hỏi ngày 18 tháng 5 lúc 5:46May 18 at 5:46

Hướng dẫn python function without parentheses - hàm python không có dấu ngoặc đơn

12

Bạn có thể sử dụng hàm

def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
72 trong Python để chuyển đổi chuỗi thành một cuộc gọi chức năng:

def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)

Ở đây chúng tôi lấy X và Y làm đầu vào từ người dùng. x Biểu thị hàm được gọi và y đóng vai trò là tham số. Sau đó, chúng tôi chỉ cần gọi

def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
72 và chuyển nó một chuỗi để đánh giá bao gồm cuộc gọi chức năng như với dấu ngoặc đơn.

Bạn chỉ có thể đặt mã này vào một vòng lặp vô hạn để có thể liên tục đánh giá các chức năng theo cách này.

Đã trả lời ngày 18 tháng 5 lúc 5:55May 18 at 5:55

Hướng dẫn python function without parentheses - hàm python không có dấu ngoặc đơn

Bemwa Malakbemwa MalakBemwa Malak

1.0131 Huy hiệu vàng5 Huy hiệu bạc17 Huy hiệu đồng1 gold badge5 silver badges17 bronze badges

Nhìn chung có 4 lần sử dụng cho dấu ngoặc đơn

def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
74 trong Python.

Nội dung chính ShowShow

  • Hàm Gọi -
  • Trả về các chức năng -
  • Vượt qua các chức năng -
  • Làm thế nào để bạn trả lại một chuỗi mà không có dấu ngoặc đơn trong Python?
  • Bạn có cần dấu ngoặc đơn để trở lại trong Python không?
  • Làm thế nào để bạn không in dấu ngoặc đơn trong Python?
  • Trả về {} có nghĩa là gì trong Python?

  1. Từ khóa Python Return thoát ra một chức năng và hướng dẫn Python tiếp tục thực hiện chương trình chính.Từ khóa trả về có thể gửi một giá trị trở lại chương trình chính.Một giá trị có thể là một chuỗi, một tuple hoặc bất kỳ đối tượng nào khác.Điều này rất hữu ích vì nó cho phép chúng tôi xử lý dữ liệu trong một hàm.exits a function and instructs Python to continue executing the main program. The return keyword can send a value back to the main program. A value could be a string, a tuple, or any other object. This is useful because it allows us to process data within a function.
  2. Nhìn chung có 4 lần sử dụng cho dấu ngoặc đơn
    def fun(function, value):
        eval(function + f'({value})')
    
    def add(value):
        x = value
        print(x)
    
    x,y = input().split()
    
    fun(x,y)
    
    74 trong Python.
  3. Nội dung chính Show
  4. Hàm Gọi -

    decision = (is_female and under_30 and single
                or
                is_male and above_35 and single)

Trả về các chức năng -

Vượt qua các chức năng -

Làm thế nào để bạn trả lại một chuỗi mà không có dấu ngoặc đơn trong Python?

Nó hoạt động giống như hầu hết các ngôn ngữ chính khác - đó là một cấu trúc để buộc ưu tiên đánh giá, giống như trong một công thức toán học. Điều đó cũng có nghĩa là nó chỉ được sử dụng khi cần thiết, như khi bạn cần đảm bảo các bổ sung và phép trừ xảy ra đầu tiên trước khi nhân và phân chia.

Đó là một cấu trúc để nhóm các giá trị bất biến với nhau trong cùng một tinh thần như một ký hiệu tập hợp tương tự trong toán học. Chúng tôi gọi đây là một tuple trong Python. Tuple cũng là một loại cơ bản. Đó là một cấu trúc để tạo ra một bộ tuple trống và lực lượng lực lượng ưu tiên.

Nó được sử dụng để nhóm các tên đã nhập cùng nhau trong các câu lệnh nhập để bạn không phải sử dụng dấu phân cách đa dòng
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
75. Điều này chủ yếu là phong cách.statement. So if you only use
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
14 in your multiple assignment statements and tuple constructions, omit the
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
74, but if you use
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
74 for value unpacking and tuple constructions, use
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
74 when you are returning multiple values in
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

4. Keep it consistent.

Trong các tuyên bố dài như

  • Khi chúng ta gọi một chức năng với dấu ngoặc đơn, chức năng sẽ được thực thi và trả về kết quả cho người được gọi.function with parentheses, the function gets execute and returns the result to the callable.function with parentheses, the function gets execute and returns the result to the callable.
  • Trong một trường hợp khác, khi chúng ta gọi một hàm không có dấu ngoặc đơn, một tham chiếu chức năng sẽ được gửi đến gọi có thể gọi thay vì thực hiện chính chức năng.function without parentheses, a function reference is sent to the callable rather than executing the function itself.function without parentheses, a function reference is sent to the callable rather than executing the function itself.

Hãy để thảo luận về 3 khái niệm quan trọng:

  • Gọi các chức năng
  • Trả về các chức năng
  • Vượt qua các chức năng

Hàm Gọi -

Hàm dưới đây thực hiện một tác vụ đơn giản, nối chuỗi. Ở đây chúng tôi sẽ gọi hàm `Concatenate_String` có và không có dấu ngoặc đơn và xem sự khác biệt.

def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
19
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
60
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
61
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
62
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
63
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
64
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
65
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
66
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
67
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
68
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
63

    decision = (is_female and under_30 and single
                or
                is_male and above_35 and single)

60
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
65
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
66
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

7
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
68
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
63
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

4
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
64

    decision = (is_female and under_30 and single
                or
                is_male and above_35 and single)

68

    decision = (is_female and under_30 and single
                or
                is_male and above_35 and single)

69
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

60
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
65
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
60
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

63
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

64__5555555
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

67
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

68
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

69
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

66
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

67
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
12
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

60
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
65
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
15
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

67
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

68
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
18
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

66
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

67
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
12

Đầu ra

Function call with Parentheses: 
Hello, George
Function call without Parentheses:

Đối với trường hợp đầu tiên, khi chúng tôi gọi

Function call with Parentheses: 
Hello, George
Function call without Parentheses:

72, chức năng đã thực thi và trả về chuỗi được nối. Và trong trường hợp thứ hai, khi chúng tôi gọi
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
15, tức là không có dấu ngoặc đơn, một tham chiếu được chuyển đến có thể gọi thay vì tự thực hiện chức năng. Ở đây có thể gọi có thể quyết định phải làm gì với tài liệu tham khảo.And, for the second case, when we call
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
15 i.e. without parentheses, a reference is passed to the callable rather than executing the function itself. Here the callable can decide what to do with the reference.
And, for the second case, when we call
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
15 i.e. without parentheses, a reference is passed to the callable rather than executing the function itself. Here the callable can decide what to do with the reference.

Trả về các chức năng -

Từ các cuộc thảo luận ở trên, bạn có thể hiểu rằng, khi hàm được gọi với dấu ngoặc đơn, mã được thực thi và trả về kết quả. Và, khi nó được gọi là không có dấu ngoặc đơn, một tham chiếu chức năng được trả lại cho Callable. Vì vậy, điều gì xảy ra khi một hàm được mã hóa cùng với câu lệnh trả về với dấu ngoặc đơn và không có dấu ngoặc đơn. Hãy để đi qua một ví dụ.So, what happens when a function is coded along with a return statement with parentheses and without parentheses. Let’s go through an example.
So, what happens when a function is coded along with a return statement with parentheses and without parentheses. Let’s go through an example.

Với dấu ngoặc đơn

def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
19
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
60
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
61
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
62
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
63
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
64
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
65
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
66
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
67
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
68
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
63

    decision = (is_female and under_30 and single
                or
                is_male and above_35 and single)

60
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
65
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
66
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

7
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
6 8
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
63
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

4
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
64

    decision = (is_female and under_30 and single
                or
                is_male and above_35 and single)

68

    decision = (is_female and under_30 and single
                or
                is_male and above_35 and single)

69
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

60
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
65
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
60
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

63
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

64__5555555
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

60
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
65
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
15

Đầu ra

Đối với trường hợp đầu tiên, khi chúng tôi gọi

Function call with Parentheses: 
Hello, George
Function call without Parentheses:

72, chức năng đã thực thi và trả về chuỗi được nối. Và trong trường hợp thứ hai, khi chúng tôi gọi
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
15, tức là không có dấu ngoặc đơn, một tham chiếu được chuyển đến có thể gọi thay vì tự thực hiện chức năng. Ở đây có thể gọi có thể quyết định phải làm gì với tài liệu tham khảo.And, for the second case, when we call
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
15 i.e. without parentheses, a reference is passed to the callable rather than executing the function itself. Here the callable can decide what to do with the reference.

Đầu ra

def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
1

Đối với trường hợp đầu tiên, khi chúng tôi gọi

Function call with Parentheses: 
Hello, George
Function call without Parentheses:

72, chức năng đã thực thi và trả về chuỗi được nối. Và trong trường hợp thứ hai, khi chúng tôi gọi
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
15, tức là không có dấu ngoặc đơn, một tham chiếu được chuyển đến có thể gọi thay vì tự thực hiện chức năng. Ở đây có thể gọi có thể quyết định phải làm gì với tài liệu tham khảo.And, for the second case, when we call
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
15 i.e. without parentheses, a reference is passed to the callable rather than executing the function itself. Here the callable can decide what to do with the reference.

Trả về các chức năng -

Từ các cuộc thảo luận ở trên, bạn có thể hiểu rằng, khi hàm được gọi với dấu ngoặc đơn, mã được thực thi và trả về kết quả. Và, khi nó được gọi là không có dấu ngoặc đơn, một tham chiếu chức năng được trả lại cho Callable. Vì vậy, điều gì xảy ra khi một hàm được mã hóa cùng với câu lệnh trả về với dấu ngoặc đơn và không có dấu ngoặc đơn. Hãy để đi qua một ví dụ.So, what happens when a function is coded along with a return statement with parentheses and without parentheses. Let’s go through an example.

Với dấu ngoặc đơn

def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
19
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
60
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
61
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
62
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
63
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
64
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
65
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
66
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
67
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
68
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
63

    decision = (is_female and under_30 and single
                or
                is_male and above_35 and single)

60
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
65
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
66
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

7
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
6 8
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
63
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

4
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
64

    decision = (is_female and under_30 and single
                or
                is_male and above_35 and single)

68

    decision = (is_female and under_30 and single
                or
                is_male and above_35 and single)

69
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

60
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
65
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
60
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

63
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

64__5555555
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

60
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
65
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
15

Đầu ra

Đối với trường hợp đầu tiên, khi chúng tôi gọi

Function call with Parentheses: 
Hello, George
Function call without Parentheses:

72, chức năng đã thực thi và trả về chuỗi được nối. Và trong trường hợp thứ hai, khi chúng tôi gọi
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
15, tức là không có dấu ngoặc đơn, một tham chiếu được chuyển đến có thể gọi thay vì tự thực hiện chức năng. Ở đây có thể gọi có thể quyết định phải làm gì với tài liệu tham khảo.And, for the second case, when we call
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
15 i.e. without parentheses, a reference is passed to the callable rather than executing the function itself. Here the callable can decide what to do with the reference.

Output:


    decision = (is_female and under_30 and single
                or
                is_male and above_35 and single)

6

Trả về các chức năng -

Function call with Parentheses: 
Hello, George
Function call without Parentheses:

6

Từ các cuộc thảo luận ở trên, bạn có thể hiểu rằng, khi hàm được gọi với dấu ngoặc đơn, mã được thực thi và trả về kết quả. Và, khi nó được gọi là không có dấu ngoặc đơn, một tham chiếu chức năng được trả lại cho Callable. Vì vậy, điều gì xảy ra khi một hàm được mã hóa cùng với câu lệnh trả về với dấu ngoặc đơn và không có dấu ngoặc đơn. Hãy để đi qua một ví dụ.And, when we code subfunction without parentheses in a return statement, the main function passes the sub-function reference to the callable rather than executing it. Here the callable decides what to do with the reference.
And, when we code subfunction without parentheses in a return statement, the main function passes the sub-function reference to the callable rather than executing it. Here the callable decides what to do with the reference.

Vượt qua các chức năng -

Bạn có thể chuyển một hàm như một đối số bằng cách tạo tham chiếu, gọi hàm mà không có dấu ngoặc đơn và cung cấp nó như một đối số. Hãy cùng xem xét mã.

def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
19
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
60
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
61
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
62
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
63
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
64
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
65
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
66
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
67
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
68
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
63

    decision = (is_female and under_30 and single
                or
                is_male and above_35 and single)

60
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
65
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
66
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

7
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
68
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
63
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
19
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
752

def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
753

Function call with Parentheses: 
Hello, George
Function call without Parentheses:

4
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
64

    decision = (is_female and under_30 and single
                or
                is_male and above_35 and single)

68
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

79
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
63
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

4
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

00
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
19
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

84
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
63
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
64
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
65
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

63
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
63

    decision = (is_female and under_30 and single
                or
                is_male and above_35 and single)

60
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
65
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

65
def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
63
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

4
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

95
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

67
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

97

Output:

def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
1

Trong trường hợp này, tham chiếu của

def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
15 được chuyển cho
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

99 như một đối số.
Function call with Parentheses: 
Hello, George
Function call without Parentheses:

7

Bên trong Function_Call, nó thực thi

def fun(function, value):
    eval(function + f'({value})')

def add(value):
    x = value
    print(x)

x,y = input().split()

fun(x,y)
15 bằng cách sử dụng tham chiếu và trả về kết quả cho người được gọi.Làm thế nào để bạn trả lại một chuỗi mà không có dấu ngoặc đơn trong Python?

Làm thế nào để bạn trả lại một chuỗi mà không có dấu ngoặc đơn trong Python?

Để chuyển đổi một tuple thành một chuỗi mà không có dấu ngoặc đơn: hãy gọi phương thức str.join () trên một dấu phân cách chuỗi. Thông qua phương thức Tuple sang phương thức nối (). Kết quả sẽ là một chuỗi chứa các phần tử tuple được phân tách bởi dấu phân cách được cung cấp.Call the str.join() method on a string separator.Pass the tuple to the join() method. The result will be a string containing the tuple elements separated by the provided separator.Call the str. join() method on a string separator. Pass the tuple to the join() method. The result will be a string containing the tuple elements separated by the provided separator.

Bạn có cần dấu ngoặc đơn để trở lại trong Python không?

Mặt khác, dấu ngoặc đơn luôn được yêu cầu trong một cuộc gọi chức năng. Nếu bạn quên chúng, thì bạn sẽ không gọi hàm mà tham khảo nó như một đối tượng chức năng. Để làm cho các chức năng của bạn trả về một giá trị, bạn cần sử dụng câu lệnh Python Return. Đó là những gì bạn sẽ bao gồm từ thời điểm này.. If you forget them, then you won't be calling the function but referencing it as a function object. To make your functions return a value, you need to use the Python return statement. That's what you'll cover from this point on.. If you forget them, then you won't be calling the function but referencing it as a function object. To make your functions return a value, you need to use the Python return statement. That's what you'll cover from this point on.

Làm thế nào để bạn không in dấu ngoặc đơn trong Python?

Trong Python 3, không còn có thể in mà không có dấu ngoặc đơn.Lý do tại sao là vì in từng là một tuyên bố trong Python 2. Trong Python 3 in () là một hàm.Như bạn đã biết, một cuộc gọi chức năng luôn yêu cầu dấu ngoặc đơn.. The reason why is because print used to be a statement in Python 2. In Python 3 print() is a function. As you know, a function call always requires parenthesis.. The reason why is because print used to be a statement in Python 2. In Python 3 print() is a function. As you know, a function call always requires parenthesis.

Trả về {} có nghĩa là gì trong Python?

Từ khóa Python Return thoát ra một chức năng và hướng dẫn Python tiếp tục thực hiện chương trình chính.Từ khóa trả về có thể gửi một giá trị trở lại chương trình chính.Một giá trị có thể là một chuỗi, một tuple hoặc bất kỳ đối tượng nào khác.Điều này rất hữu ích vì nó cho phép chúng tôi xử lý dữ liệu trong một hàm.exits a function and instructs Python to continue executing the main program. The return keyword can send a value back to the main program. A value could be a string, a tuple, or any other object. This is useful because it allows us to process data within a function.exits a function and instructs Python to continue executing the main program. The return keyword can send a value back to the main program. A value could be a string, a tuple, or any other object. This is useful because it allows us to process data within a function.