0% found this document useful (0 votes)
9 views3 pages

Numeric Types: Int Float Complex

Uploaded by

Balaji Bala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Numeric Types: Int Float Complex

Uploaded by

Balaji Bala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Python supports various data types, each suited to different kinds of operations.

Here is an
overview of some basic and commonly used data types in Python:

1. Numeric Types

 int: Integer numbers, e.g., 1, 2, 3


 float: Floating point numbers (decimal numbers), e.g., 1.0, 3.14
 complex: Complex numbers, e.g., 1 + 2j

python
Copy code
a = 10 # int
b = 3.14 # float
c = 1 + 2j # complex

2. Sequence Types

 str: String, a sequence of characters, e.g., "hello"


 list: Ordered, mutable collection of items, e.g., [1, 2, 3]
 tuple: Ordered, immutable collection of items, e.g., (1, 2, 3)

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

 set: Unordered collection of unique items, e.g., {1, 2, 3}


 frozenset: Immutable version of a set, e.g., frozenset({1, 2, 3})

python
Copy code
s = {1, 2, 3} # set
fs = frozenset([1, 2, 3]) # frozenset

5. Boolean Type

 bool: Boolean values, True or False

python
Copy code
is_true = True # bool
is_false = False # bool
6. None Type

 NoneType: Represents the absence of a value, e.g., None

python
Copy code
x = None # NoneType

Examples of Basic Operations with Different Data Types

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

You might also like