Numeric Types: Int Float Complex
Numeric Types: Int Float Complex
Here is an
overview of some basic and commonly used data types in Python:
1. Numeric Types
python
Copy code
a = 10 # int
b = 3.14 # float
c = 1 + 2j # complex
2. Sequence Types
python
Copy code
s = "hello" # str
lst = [1, 2, 3] # list
tup = (1, 2, 3) # tuple
3. Mapping Type
dict: Unordered collection of key-value pairs, e.g., {'name': 'Alice', 'age': 25}
python
Copy code
d = {'name': 'Alice', 'age': 25} # dict
4. Set Types
python
Copy code
s = {1, 2, 3} # set
fs = frozenset([1, 2, 3]) # frozenset
5. Boolean Type
python
Copy code
is_true = True # bool
is_false = False # bool
6. None Type
python
Copy code
x = None # NoneType
Numeric Types
python
Copy code
# int
x = 5
y = 2
print("Addition:", x + y)
print("Subtraction:", x - y)
# float
a = 5.0
b = 2.5
print("Multiplication:", a * b)
print("Division:", a / b)
# complex
c1 = 1 + 2j
c2 = 2 + 3j
print("Complex Addition:", c1 + c2)
Sequence Types
python
Copy code
# str
s1 = "hello"
s2 = "world"
print("Concatenation:", s1 + " " + s2)
print("Repetition:", s1 * 3)
# list
lst = [1, 2, 3]
lst.append(4)
print("List after append:", lst)
# tuple
tup = (1, 2, 3)
print("First element of tuple:", tup[0])
Mapping Type
python
Copy code
# dict
person = {'name': 'Alice', 'age': 25}
print("Name:", person['name'])
person['city'] = 'New York'
print("Updated dict:", person)
Set Types
python
Copy code
# set
s = {1, 2, 3, 2}
print("Set:", s)
# frozenset
fs = frozenset([1, 2, 3])
print("Frozen set:", fs)
Boolean Type
python
Copy code
# bool
is_raining = True
is_sunny = False
print("Is it raining?", is_raining)
print("Is it sunny?", is_sunny)
None Type
python
Copy code
# NoneType
x = None
print("Value of x:", x)
These examples cover basic operations and data manipulations using the fundamental data
types available in Python.
4o