+ 11

Can anybody explain me the line of code pls.

what is happening here while declaring the function checkio? ``` def checkio(text: str) -> str: ```

16th Dec 2018, 4:16 PM
🄼🄼🄷🄺
🄼🄼🄷🄺 - avatar
11 Réponses
+ 12
It's basically the same as def checkio(text). "text: str" means that the parameter "text" is expected to be of type str, "-> str" means that the return value of the function is also a string. This is more or less just an information for the user or other programmers. The interpreter just ignores these statements and even if you call the function with an integer parameter or let it return a boolean (or nothing at all), there won't be any warning or error message.
16th Dec 2018, 4:28 PM
Anna
Anna - avatar
16th Dec 2018, 4:28 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 5
It implies that the function will return a string value. But, like I said, if it actually returns an integer or something else doesn't make any difference. It's just an annotation so that other programmers know what kind of return value they can expect from the function ☺️
16th Dec 2018, 4:47 PM
Anna
Anna - avatar
+ 2
create a function called checkio. The function accepts a parameter of type str (iirc if it isn't it will convert if possible) and returns a str
16th Dec 2018, 4:26 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
You're basically annotating.
16th Dec 2018, 4:30 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
Thanks all of you
16th Dec 2018, 4:31 PM
🄼🄼🄷🄺
🄼🄼🄷🄺 - avatar
+ 1
Q to Anna, Does ->str also means that return str or just referring return type has to be str? Hope you understand what i am saying
16th Dec 2018, 4:44 PM
🄼🄼🄷🄺
🄼🄼🄷🄺 - avatar
+ 1
Thanks Anna👏
16th Dec 2018, 4:50 PM
🄼🄼🄷🄺
🄼🄼🄷🄺 - avatar
+ 1
You are telling python which type you expect parameter to be and also what type of data you will return.
17th Dec 2018, 6:43 AM
Adrian
Adrian - avatar
- 1
I'm not do anything but I'm faster a boy
18th Dec 2018, 6:18 PM
Dean Yobron
Dean Yobron - avatar
- 1
My real lover is python programming
18th Dec 2018, 6:20 PM
Dean Yobron
Dean Yobron - avatar