USER INPUT IN PYTHON | PYTHON FOR ABSOLUTE BEGINNERS | USER INPUT FUNCTION IN PYTHON WITH EXAMPLES смотреть онлайн
#
#pythonprogramming #userinputinpython #userinputfunction #pythonforbeginners #pythontutorial #pythonforabsolutlebeginners #bestpythonguidetobeginners #python
INPUT IN PYTHON | PYTHON FOR ABSOLUTE BEGINNERS | USER INPUT FUNCTION IN PYTHON WITH EXAMPLES
_____________________________________________________________
_____________________________________________________________
In this video, we're going to learn about
actually getting data from our users,
so that our programmers can start being a bit more dynamic.
Imagine you've got your name,
and it's Jose, and you want the user's name.
But, how do you get it?
Do you expect the user to edit the programme
so they can put their name in here?
Finally, what you'll want to do is to print,
you know something like "Hello \{your_name\}.
"My name is \{my_name\}."
Let's say we have a simple programme like this.
So how do you get the user's name?
Because if you run this right now,
you'll get "Hello, empty string.
"My name is Jose."
If the user has to come in and edit the programme
then, you know, this'll work, right?
But, how are you gonna share this with users
that don't know any programming?
So, what we have to do is we have to first
ask the user for their name,
and allow them to type something here in this text console
and then use that name inside our programme.
So here is where the input function comes in.
So we will type input("Enter your name: ")
and what this is going to do is it's going to
open up a prompt here in the console
and notice that the programme is stopped
until we press the Enter key.
So if I type Rolf now, then you'll see that we get back
"Hello Rolf.
"My name is Jose."
This tells you one thing about the input function,
which is that the thing that the user typed
came back to us, and it must have been a string.
Because it contains characters, it is not an integer
and it is not a float, otherwise it would have to be numbers
and you would be able to do maths on it.
So it must be a string.
And that is something that always happens
with the input function.
Anything the user types, even if it is
the number 35, is a string.
A string that contains the characters three and five.
With that in mind, let's try something else.
Let's try asking the user for their age.
And then we're going to print
"You have lived for \{age * 12\} months."
So a very popular first programme,
we're gonna ask the user for their age,
and then we're going to say, for example,
they might in there enter three there,
we're gonna say, "You have lived for 36 months."
Right?
But remember, that the age variable has a string in it.
The input function always gives you back a string,
even if you enter a number.
So, we aren't turning this into a number.
What is going to happen when we multiply a string by 12?
Well, let me type three in here.
And you get 333333333333.
You get 12 threes.
Because age times 12 is more or less the same as
age plus age plus age plus age 12 times.
And remember what happens when we add two strings together?
They get joined together.
They get concatenated.
So, by multiplying a string by a number,
really what you're getting is 12 of those strings.
What you have to do is you have to turn it into an integer.
So, the same way that we used S-T-R to turn a integer,
or another number into a string,
we can use I-N-T or int to turn a string into an integer.
So, we will turn age into an integer
and put it inside age_num,
and then we will do age_num times 12.
And that works just as well.
Now something important about Python
that you're gonna see quite a lot
is that when you evaluate one of these things here,
that becomes the value that the user has given you.
So, here's what I mean.
This text that I've got selected here
is three when your programme runs.
So, if the user is going to enter three in your programme,
this entire text I've got selected
is exactly identical to you just typing three in there.
Means exactly the same thing.
Of course, the user can enter something different,
if they'd like, so this is why this is a dynamic value.
But, if they enter three, it's the same thing
as having three in there.
If they enter 35, it's the same thing as having 35 in there.
So, we could do age equal int of 35, right?
And then we would not need this age_num there,
and we could do this.
But, how do we get the dynamic value
instead of the static 35 string?
We use the input function that we had just a moment ago.
So you can do this in Python
_________
#integer_input_in_python
#user_input_python_3
how to take string input in python
python get input from console
how to take integer input in python 3
multiple input in python
write a program to take an input from the user and print that input in python
array input in python
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «USER INPUT IN PYTHON | PYTHON FOR ABSOLUTE BEGINNERS | USER INPUT FUNCTION IN PYTHON WITH EXAMPLES» бесплатно и без регистрации, вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.