Python. Variables. Data types. Converting data types of variables. distinguish between data types in Python convert data types of variables

Variables in Python. Data types. Converting data types of variables.

Подписывайтесь на канал "Программирование на Python"


hello = 'hi'
hello2 = hello

Rules for creating variables in Python:

  • Variable names must start with a letter or underscore.
  • Variable names cannot start with a number.
  • A variable name can only contain letters, numbers, and underscores (A - z, 0-9, and _).
  • Variable names are case sensitive (num, Num and NUM are three different variables).
  • Reserved words (keywords) cannot be used to name a variable.

number = 10        # variable number of integer type assigns the value 10
pi = 3.14          # floating point pi is assigned the value 3.14
word = "Hello"     # variable word of string type assigns the value "Hello"
print(number, pi, word) # output values of variables

Variable can change value in a program. 

word = "Astana"
print("2017 - ", word)
print("2018 –", word)
word = "Nur-Sultan"
print("2019 –", word)
print("2020 –", word)
print("2021 –", word)

Output data:

2017 - Astana
2018 - Astana
2019 – Nur-Sultan
2020 – Nur-Sultan
2021 – Nur-Sultan




Ex.1 Data types in Python (Author: Mr. Halil Mali - CS teacher of NIS Uralsk) 

Категория: Programming languages | Добавил: bzfar77 (05.09.2021)
Просмотров: 84 | Теги: String, Boolean, Python, Conversion, integer, variable, Float, data type | Рейтинг: 0.0/0
Всего комментариев: 0