Python Constants, Literals and Data Types (Beginner Guide)
Python Constants, Literals and Data Types (Beginner Guide) In Python, data is stored and handled using different types of values and structures. In this article, we will understand constants, literals, and data types in a simple way. Constants in Python A constant is a special type of variable whose value cannot be changed during the program. Although Python does not have built-in constant variables, we usually define constants using a separate file. Example: import constant print(constant.PI) # 3.14 print(constant.GRAVITY) # 9.8 Here, PI and GRAVITY are treated as constant values. Literals in Python Literals are fixed values used in a program. They represent data directly. Types of Literals: Numeric literals String literals Boolean literals None literal Bytes and Bytearray Raw string Numeric separators Collection literals -list, tuple, set, etc Data Types in Python Python supports different types of data to store values. 1. String (Text Data Type) A string is a se...