All language subtitles for 3. Default values for parameters

af Afrikaans
ak Akan
sq Albanian
am Amharic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

1 1

Hi and welcome back. 2

2

In this video, we're looking 3

3

at default values for parameters. 4

4

If you already know a bit of Python, 5

5

you may wonder why we didn't cover this earlier. 6

6

And quite simply the reason is that we didn't need it. 7

7

Now we do and we're gonna start looking 8

8

at a couple of instances where having default values 9

9

with parameters is gonna be useful. 10

10

So let's get right on it. 11

11

Whenever we call a function that has parameters, 12

12

we are expected to give it an equal number of parameters. 13

13

We already know this, so I'll show you some example code. 14

14

Here's some accounts, like a checking account. 15

15

Let's see, that has $1,958 in it 16

16

or pounds if you're in the UK. 17

17

3695.50 in your savings. 18

18

That's a pretty respectable amount of money. 19

19

Then we're gonna have a function add_balance, 20

20

which is going to take an amount, 21

21

which is going to be a float and a name, 22

22

which is going to be a string. 23

23

And it's going to return a float. 24

24

The reason I'm including it here, 25

25

the type hinting that we've looked at in the past. 26

26

Also, just for completeness, I am going to say function 27

27

to update the balance of an account 28

28

and return the new balance. 29

29

Include that log string in there 30

30

just so you know what this function's all about. 31

31

As you can see, this function, add_balance, 32

32

is going to update the balance of an account 33

33

and return the new balance. 34

34

The two arguments it takes are the amount 35

35

to increase the balance by 36

36

and the name of the account that we're gonna change. 37

37

Then it's gonna go over to your accounts global dictionary 38

38

and it's going to change it. 39

39

So, accounts name 40

40

plus equal amount 41

41

and then it's going to return accounts name. 42

42

It's going to return the new balance of the account. 43

43

Accounts name, for example, for checking 44

44

is going to be 1958. 45

45

Let's say we say 200 in here is gonna go, 46

46

increase it by 200. 47

47

I'm not even gonna try to do the math here. 48

48

Then it's going to return the new amount 49

49

of accounts name, so that should be a float. 50

50

However, what we can do, of course, 51

51

is add balance 500.00 to savings 52

52

and then print account savings 53

53

and it should tell us the new balance 54

54

which should be in the four thousands. 55

55

Oh, sorry, accounts savings. 56

56

As you can see, 4,195.5. 57

57

Notice how the zero at the end gets dropped, 58

58

but in my code I like having two decimal places 59

59

for currency just to keep things clearer. 60

60

What you didn't know that you could do is you can say 61

61

that by default, all new balances are going to go 62

62

to your checking account. 63

63

So the name here is going to be checking, by default. 64

64

And the way we do that is we add equal checking. 65

65

Okay, so the name is a string 66

66

and its' default value is checking. 67

67

That means that if we do not pass a string 68

68

through this argument, which we can do now, 69

69

we can not pass a string to it. 70

70

We can not pass anything to it 71

71

and we print out the checking at the end, 72

72

we should see it has increased by $500, 73

73

not 500 units. 74

74

If you don't wanna use type hinting, 75

75

then all you have to do is get rid of that. 76

76

Okay and this stays the same, name equals checking. 77

77

And that's that, okay. 78

78

Frequently, actually, if you don't have type hinting, 79

79

you'll see this written like so, without the spaces 80

80

and when you do have type hinting, 81

81

you'll see it written like so, all with spaces. 82

82

It's up to you how many spaces you want 83

83

to put in there, whether you wanna put spaces 84

84

or not spaces, totally fine. 85

85

Now, something important that you have to know 86

86

about these names arguments, this is what they're called 87

87

as soon as you have the default argument there, 88

88

is that you cannot have this 89

89

here, oops sorry, 90

90

you cannot have this here. 91

91

This will be illegal. 92

92

When you run it, it'll tell you here. 93

93

Syntax error, known default argument 94

94

follows default argument. 95

95

So you cannot do this. 96

96

Any argument that has a default value 97

97

has to follow arguments that do not 98

98

have default values. 99

99

So in this case, the amount 100

100

does not have a default value. 101

101

The name does, so the name has to go at the end. 102

102

If you have many arguments, 103

103

some of which have default values, 104

104

they must all go at the end. 105

105

Okay? 106

106

That's it. 107

107

This is default values for arguments. 108

108

You can have many arguments, many default values. 109

109

One default value per argument, 110

110

of course and we're gonna learn more 111

111

about these default values 112

112

and how to use them in subsequent videos, 113

113

in just a couple of videos. 114

114

In fact, in the next video, 115

115

and in coming videos too. 116

116

So, that's it for this one. 117

117

I'll see you on the next one.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.