When I pass an argument to a function, as I understand it, the function does not understand what kind of data I want to work with. The essence of the question is, can I explicitly indicate that the list / dictionary / tuple is passed to the function as an argument ... and in the function body I work with the list / dictionary / tuple ...?
Here is what I get:
def print_magicians (magicians): for magician in magicians: print(magician) def great_magicians (magicians): for i in range(len(magicians)): temp = magicians[i] magicians[i] = "Great " + temp magicians_list = ["ΠΡΠ΄ΠΈΠ½ΠΈ", "ΠΠΎΠΏΠ΅ΡΡΠΈΠ»ΡΠ΄", "ΠΠ»Π΅ΠΉΠ½"] print_magicians(magicians_list) great_magicians(magicians_list) print_magicians(magicians_list)
Functions def great_magicians (magicians) I accept or expect any type of data as an argument (I donβt know how to put it right) and in the end I canβt work with it as a list (call its methods). And if, say, there is not a list, but a string or a number being passed in as an argument, then what happens? After C similar languages ββin which there was a strict typification not everything is clear.
def print_magicians(magicians: list):
but this is only a hint about the type, the interpreter will not swear if another object gets there - gil9red 1:56 pmmagicians.append(1)
- gil9redb = [1,2,3]
->isinstance(b, list)
->True
- S. Nick