Python Datatypes
http:s//www.theitroad.com
Python has several built-in data types that can be used to store different kinds of values. The most common data types in Python include:
- Integers (int): Whole numbers such as 1, 2, 3, etc.
- Floating-point numbers (float): Decimal numbers such as 3.14, 2.0, etc.
- Strings (str): Ordered sequences of characters such as "hello", "world", etc.
- Booleans (bool): Logical values that can be either True or False.
- Lists: Ordered collections of objects that can be of different data types.
- Tuples: Immutable ordered collections of objects that can be of different data types.
- Sets: Unordered collections of unique objects.
- Dictionaries: Unordered collections of key-value pairs.
Here are some examples of creating variables of different data types:
# Integers
x = 5
y = 10
z = -3
# Floats
a = 3.14
b = 2.0
c = -1.5
# Strings
name = "John"
message = "Hello, world!"
# Booleans
is_student = True
is_teacher = False
# Lists
my_list = [1, 2, "hello", True]
# Tuples
my_tuple = (1, "hello", 3.14)
# Sets
my_set = {1, 2, 3}
# Dictionaries
my_dict = {"name": "John", "age": 25, "is_student": True}
Python also has some other data types, such as complex numbers and byte arrays, but they are less commonly used in everyday programming.
