Data Types

Carson West

Variable Naming Conventions

Data Types

Python has several built-in data types. Here’s a breakdown:

Example Code:

my_int = 10
my_float = 3.14
my_string = "Hello, world!"
my_list = 1, 2, 3
my_tuple = (4, 5, 6)
my_dict = {"a": 1, "b": 2}
my_set = {1, 2, 3}
my_bool = True

Type Conversion:

Python allows type conversion (casting) between data types using functions like int(), float(), str(), etc. However, not all conversions are possible (e.g., converting a string containing letters to an integer will raise an error).

x = 10  # int
y = float(x)  # convert to float
z = str(x)   # convert to string

Type Conversion Mutability Immutability Sequence Types in Detail Dictionary Methods