What are Python variables? Give an example of declaring numeric data types.
Answer: Python data types classify values. Numeric types are int, float and complex, for example 5, 2.5 and 3+4j. A string is an ordered sequence of characters such as 'Hello' and supports indexing, slicing and concatenation. Boolean type has only True and False and results from comparisons. Other common types are list, tuple, dict and set.\
Python data types. Every value in Python is an object with a type, and the built-in function type reports that type at runtime. Numeric types include integers, which have unlimited precision, floating point numbers, which follow binary floating point rules, and complex numbers written with a real and imaginary part. The Boolean type has exactly two values, True and False, and it is a subclass of integer, which is why Booleans can appear in arithmetic. The string type holds an ordered, immutable sequence of characters and supports indexing, slicing, concatenation and a large family of methods. Collection types include lists, which are ordered and mutable, tuples, which are ordered and immutable, dictionaries, which map hashable keys to values, and sets, which hold unique unordered elements. The special value None represents the absence of a value and has its own type. Python converts between compatible types with int, float, str, bool and the collection constructors, and some operations convert implicitly, for example comparing an integer with a float. Immutable objects cannot be changed after creation, so operations on strings and tuples return new objects, while lists and dictionaries are modified in place. A good answer names each category, gives an example literal, states whether it is mutable, shows the result of type and explains one conversion. A small table with columns for type, example and mutability, followed by a program that prints each type, makes the answer complete.
Result: Numeric types store numbers, strings store text and boolean type stores logical truth values.
Key Points
- Python Data Types
- int, float and complex form numeric types.
- str holds text; bool holds True or False.