Python data types
Introduction to Python Data Types
Python is a high-level programming language that supports various data types. A data type
is a classification of data based on its format, size, and set of values it can hold. Python has
several built-in data types that can be used to store and manipulate data.
*1. Integers (int)*
Integers are whole numbers, either positive, negative, or zero. They are used to represent
numerical values.
Example:
```
X=5
Y = -3
Z=0
```
*2. Floats (float)*
Floats are decimal numbers. They are used to represent numerical values with a fractional
part.
Example:
```
X = 3.14
Y = -0.5
Z = 0.0
```
Page 2: More Python Data Types
*3. Strings (str)*
Strings are sequences of characters. They are used to represent text.
Example:
```
X = “hello”
Y = ‘hello’
Z = “””This is a multi-line string”””
```
*4. Boolean (bool)*
Booleans are true or false values. They are used to represent logical values.
Example:
```
X = True
Y = False
```
*5. List (list)*
Lists are ordered collections of items. They are used to represent collections of data.
Example:
```
X = [1, 2, 3]
Y = [“a”, “b”, “c”]
Z = [1, “a”, 3.14]
```
Page 3: Even More Python Data Types and Conclusion
*6. Tuple (tuple)*
Tuples are ordered, immutable collections of items. They are used to represent collections
of data that should not be changed.
Example:
```
X = (1, 2, 3)
Y = (“a”, “b”, “c”)
Z = (1, “a”, 3.14)
```
*7. Dictionary (dict)*
Dictionaries are unordered collections of key-value pairs. They are used to represent
mappings of keys to values.
Example:
```
X = {“name”: “John”, “age”: 30}
Y = {“city”: “New York”, “country”: “USA”}
```
Python has several built-in data types that can be used to store and manipulate data.
Understanding these data types is essential for any Python programmer. By using the right
data type for the job