How to set the parameters in the parameters that should be sent?

0

Gross example of what I want (which does not work):

# -*- coding: utf-8 -*-

def a(int(b), str(c)): # Isso não funciona, mas quero algo assim.
    print('Isso é um Numero: %i' %b)
    print('Isso eh uma String: %s' %c)

a(10, 'Texto')



# -*- coding: utf-8 -*-

# Não Quero fazer isso.
def a(b, c):
    # Não Quero fazer isso.
    if not ('int' in str(type(b))): return False
    if not ('str' in str(type(c))): return False

    print('Isso é um Numero: %i' %b)
    print('Isso eh uma String: %s' %c)

a(10, 'Texto')
    
asked by anonymous 09.07.2018 / 04:33

1 answer

3

Something like this?

def a(b : int, c : str):
    print('Isso é um Numero: %i' %b)
    print('Isso eh uma String: %s' %c)

It is possible since Python 3.5 and is improving support, which will culminate in 4.0 being a language with "total" support for variable typing, including parameters, members, and structure elements. Although it is not a static typing language, think of some unit tests automatically inserted for you and the compiler will have special handling. There will still be glitches, poor performance and other problems of dynamic typing, but it is already a considerable gain.

Note that it is not something of normal use, you need to use a library, as the documentation shows. If you want to learn more you have PEP484 .

Dynamic typing mainstream languages are going this way in one way or another. Just do not say that they realized that it was a mistake to have adopted dynamic typing that does not scale well, because they were right at the time, a script language should have this typing even. The problem is now that these languages have gotten public, and this audience does not want to drop their language prefer and go to one that suits them better in the new demands that are not scripts , then language resolves to be what it never been to meet these people and continue with success.

    
09.07.2018 / 05:39