Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranî)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
0 Something to point out is that when your function doesn't have a return statement, save, execute. 1
it implicitly returns a None object. 2
None is a specific object in Python which means nothing. 3
It's not an integer. 4
It's not a float. 5
It's not a string. 6
It's just None, it means nothing. 7
So Python what it does is if it doesn't find the return statement on the background it does this: 8
return None. 9
So if you execute that, ups an indentation error. 10
That's a good thing. 11
So you see that all this block here has to be the same level of indentation, if indented four lines here, 12
you have to indent for lines in here too. 13
So indentation has to be consistent. 14
That looks all right. 15
So we got the same outputs, None here and None there. 16
Some people do this mistake instead of returning, they do... 17
They use print instead of using return they use a print function. 18
The mean which works half the way. 19
So it still returns the value. 20
And it also returns None. 21
So what's going on here is that when you call the function here Python will execute all these lines 22
so it calculates the mean. 23
Then it goes to the next line so line by line it will print the mean. 24
So it will print out the mean in here and then it will look for a return statement. 25
It doesn't find it so it will return None. 26
The problem with this is that if you try to do some other operations with your mean value let's say 27
my mean is equal to the mean function 0, 3, and 4. 28
OK. 29
And I want to print out my mean plus 10. 30
So I would expect that this would give me the value of 7 is the sum divided by 3. 31
So two point something plus ten, twelve point something, but let's see what this will give me. 32
So this will give me a type error instead. 33
It's tried to add the None type which is None. 34
So this is a None type. 35
That's the type of this value. It's trying to add that to 10. 36
So my mean is None because it's returns None, and the interpreter will try to add up 37
that to 10. 38
That's not possible. 39
So that's why you shouldn't use print. 40
If I replace that with return instead, remove the parentheses, save, execute, that will give me 41
12.3. 42
That is the average plus 10. 43
However this doesn't mean you can not use print in your functions. 44
You can actually do that. 45
Let's say you just wants to print some information. 46
Started, functions started and execute that. 47
So you get the output of print in here, and then Python returns the mean, so you get the mean, 48
you store it in here, the output 49
of your function, but the value of the function is always what's you return in here. 50
So if you see that. 51
So always use return in your functions unless you have a very special reason to do so.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.