Httprunner: httprunner: httprunner: httprunner: Httprunner: Httprunner: Httprunner: Httprunner



What the hell is this? I felt so scared that I was ashamed to say I knew Python.

This is called type hints and is a new feature in python3.5. The colon after a parameter in a function is actually a type suggestion for the parameter, but it is only a suggestion, even if you do not pass it by convention. The arrow in the back is the type suggestion for the return value of the function. Here’s an example:

def demo(a, b):
    c = a + b
    return c


if __name__ == '__main__':
    print(demo(1, 2))
Copy the code

The result of the run is 3. At this point, I can also write:

def demo(a: int, b: int) -> "int":
    c = a + b
    return c


if __name__ == '__main__':
    print(demo(1, 2))
Copy the code

The result of the run is still 3. Of course, I can pass the parameter without the suggested type, for example:

Def demo (a: int, b: int) - > "int" : c = a + b return c if __name__ = = "__main__ ': print (demo (" you", "good"))Copy the code

Run result: Hello. I think this feature helps make Python projects more formal, because large projects often require multiple people to help with them, which makes the code more readable.