All language subtitles for 009 The Python Input Function.en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
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
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

Coming back to our Repl.it,

2

the Day 1 printing repl that you should have from previously,

3

I want to talk about a different function.

4

So we've seen the print function and all the things that we can do to strings

5

and use the print function and debug it.

6

But what if we wanted to be able to enter some data?

7

So if we wanted to say,

8

ask the user 'what is your name?' And we run this code,

9

you can see that being printed,

10

but there's no way for the user on this side to be able to give our code some

11

data to work with. In order to do that,

12

instead of using the print function,

13

we're going to use a different function and it's called the input function.

14

And notice how as I'm typing,

15

code intelligence is already giving me some suggestions because it thinks it

16

knows what I might want and it's right.

17

So this is what the input function looks like. This is the name of the function.

18

And again, it's followed by some parentheses. Inside the parentheses

19

is the prompt that I'm going to give the user.

20

So when I run this code, it will say, what is your name?

21

And then the cursor will stay at the end of this line because it's expecting

22

some sort of input. If I give it my name, Angela and I hit enter,

23

then this piece of data has now been passed back into my code and it now

24

replaces this part of the code.

25

So I'm passing data from over here,

26

back to over here where I can use it in my code.

27

Now notice the difference here. It looks quite similar.

28

When we run print, you can see it says what is your name?

29

and then the code execution ends and we know it ends because it's showing us

30

this little orange arrow.

31

But notice when I run input instead,

32

I don't see the orange arrow.

33

My program is actually paused right now in order for the user to provide an

34

input and it's only when I've given the input and hit enter

35

does the program end.

36

The input function looks pretty much identical to the print function,

37

but instead of the word print,

38

it's just got the word input. And inside the parentheses,

39

instead of adding what text will be printed,

40

we're adding the prompt for the user to give them a hint as to what kind of data

41

we want. And then when you run this code, it will print out the prompt,

42

but then there will be a cursor. In some places you'll see it like a flashing

43

cursor, other places,

44

it'll just be a solid cursor ready for the user to type in some piece of data.

45

So what can we do with this data? Well,

46

we can use it inside our code.

47

Remember how I said once this line of code executes and I've entered Angela as

48

the response to this input,

49

then this part of the code gets replaced by whatever it is that the user typed

50

in. So in this case it becomes Angela.

51

And what I can do with it is let's say I wanted to print something like,

52

hello Angela. Well,

53

then I can simply write Hello + input and then I'm going to close it off

54

with another set of brackets.

55

So I'm going to change my layout instead of side by side,

56

I'm going to change it to stacked.

57

And this means that I've got my code at the top and my console at the bottom.

58

This way my line can go a little bit longer without it rapping.

59

Notice what's happening here.

60

This is the input function that I showed you earlier on and this is a print

61

statement.

62

So we've got this nested inside the other. And now when I run my code,

63

what happens is it asked me what is your name?

64

So I'll write my name and then when I hit enter,

65

this part is replaced by Angela and it gets concatenated to the word hello and

66

the entire thing gets printed out down here.

67

If you find this line of code difficult to understand and to wrap your head

68

around,

69

then I recommend heading over to a website called thonny.org and downloading an

70

application called Thonny. It's completely free and it's available for Windows,

71

Mac, and Linux. And once you've installed this application,

72

you can go ahead and paste your line of code here and click on this little debug

73

symbol. And then we can click on this button,

74

which is called the step into button to step into the execution of this line of

75

code

76

to see how the computer is evaluating this code here step by step.

77

So you'll see the first thing it tries to do is it will try to run this print

78

statement. It looks inside, these parentheses to see what it needs to print.

79

So the first thing is this, Hello,

80

and it turns that into a string and then it looks at the next thing after the

81

plus sign to see what it should turn this into.

82

And this of course is the input function. So as I continue stepping into it,

83

it's actually going to execute it.

84

So it's going to run this input function and show the prompt, what is your name?

85

So that's what shows up down here.

86

And now if I enter a value in here and hit enter,

87

then that value that I put right there replaces that previous input function

88

and is now held inside the print statement.

89

So if I continue stepping through this code then you'll see it concatenates all of

90

the pieces together, and finally it just ends up with a simple print

91

Hello Angela! And if I continue stepping into it,

92

you'll see that line of code executed until there are no more instructions left.

93

So if you prefer seeing your code, um,

94

run like this step by step so that you can see what's going on,

95

then I recommend giving this a go.

96

But because of how easy it is to share these Repl.it code bases so that we're

97

working from the same place, I recommend to do most of your coding here

98

and only if you get stuck to take a single line of code and paste it into Thonny

99

to see how it's executed step-by-step. As you're learning to code,

100

there's going to be new concepts covered.

101

There's going to be things that take a little bit of thinking before you can

102

understand it.

103

So what a lot of programmers love to do is they like to comment in their code.

104

Now,

105

you might've seen this already throughout the coding exercises and the solutions

106

I provided. But in Python,

107

if you wanted a line of text to not be considered by the computer at all,

108

all you have to do is add the hashtag or pound sign in front of your text and

109

this turns it into a comment,

110

so something that the computer will completely ignore.

111

So in here you can write code as much as you like, um,

112

but it won't be executed and when you click run,

113

you'll see that this is completely ignored.

114

What I recommend is whenever you come across a new concept in the course to make

115

a comment above it so that you can explain to yourself what's actually going on

116

in the line of code below. This way

117

the next time you come across this line of code and you're not quite sure what's

118

actually happening here,

119

you can have a look at the notes that you've written for yourself in your own

120

words and hopefully it'll re-jog your memory and make it much easier to

121

comprehend what's going on.

122

In addition to adding a pound sign manually,

123

you can also highlight a line of code or simply have your cursor on a line of

124

code and hold down command and forward slash if you're on Mac or control and

125

forward slash if you're on Windows.

126

And if you want to go back or undo your changes,

127

it's simply command +z or control + z. All right,

128

so in this lesson we learned about input function,

129

we learned about putting functions inside other functions and being able to get

130

user input from the console by using the input function.

131

So now I've got a coding exercise for you in the next lesson,

132

and if you've commented this line of code thoroughly and you fully understood

133

how it works, then you'll be able to breeze through the next exercise.

134

So for all of that and more, I'll see you there.

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