Python Tutorial : Variable Data Types
Want to learn more? Take the full course at https://learn.datacamp.com/courses/intro-to-python-for-finance at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
---
All variables in Python are typed - and I don't just mean on your keyboard!
The type of a Python variable defines its properties and how it can be used.
Here are four data types in Python. Strings are text enclosed in quotes. Integers are whole numbers without decimal points, like the number 40. Floats are real numbers with a decimal point. Finally, booleans in Python are logical values, either True or False.
Note that unlike other programming languages such as C or C++, Python sets the data type of the variable based on the value that is assigned to it. The abbreviations for the data types we discussed are shown here.
It is often important to know the data type of the variable you are dealing with. To do this, you can use the function type() followed by the variable inside parentheses. We will learn more about functions in a later chapter. For now, think of functions as commands that you use to obtain specific results. In this case, we used the type() function to determine the data type of a variable, and the print() function to print the result.
As you can see here, the data type of pe_ratio is an integer.
Let's take a closer look at the Boolean data type. The Boolean data type is often the result of a conditional test involving comparison or logical operators.
In this example, a double equal sign tests whether two values are equal, and since they are equal, the result is True. If you check the type of the result, you will see that it is bool, short for boolean.
As mentioned earlier, it is important to understand the data types of variables because depending on the data type of variables, you can manipulate them differently.
Let's take a look at how strings and integers behave with the multiplication operator.
Here we assign an integer 5 to the variable x and multiply this variable by 3. The solution is 15, an integer.
Now let's assign the string 'stock' to the variable y and multiply it by 3. What happened? The string 'stock' is repeated thrice.
What happens when you try to use the addition operator? As expected, when you add 3 to the integer, you get a valid result, 8.
However, when you try to add an integer 3 to the string, you get an error. You can not combine an integer with a string directly.
If you wish to print a combination of strings and ints/floats, you first need to convert the int/float to a string. You can do this using the str() function.
As you can see here, the type() of pi is float. But after passing pi to the str() function, the type of new variable pi_string is str.
You can now combine pi_string with any string using the addition operator, as we do here.
Now that you've been introduced to variables, let's put this into practice.
#DataCamp #PythonTutorial #IntroductiontoPythonforFinance
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Python Tutorial : Variable Data Types», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.