Unit II Python
Unit II Python
UNIT-II
UNIT-II
DATATYPES:
1.Numeric types
2.Sequence types
3. Mapping type
4.Set types
5. Boolean type
6.NoneType
DATATYPES
1.Numeric types:
•int: Integer numbers (e.g., 5, -10, 0)
EXAMPLE :
x = 10
print(x) Output: 10
•float: Floating-point numbers (e.g., 3.14, -2.5, 0.0)
EXAMPLE :
y = 3.14
print(y) Output: 3.14
2.Sequence types:
•str: String of characters (e.g., "Hello", 'Python', "123")
EXAMPLE :
name = "Alice“
print(name) Output: Alice
DATATYPES
•list: Ordered collection of items (e.g., [1, 2, 3], ['a', 'b', 'c’])
EXAMPLE :
numbers = [1, 2, 3, 4]
print(numbers) Output: [1, 2, 3, 4]
3.Mapping type:
•Dict : Collection of key-value pairs (e.g., {'name': 'Alice', 'age': 30})
EXAMPLE:
person = {'name': 'Bob', 'age': 25}
print(person) Output: {'name': 'Bob', 'age': 25}
DATATYPES
4.Set types:
•set: Unordered collection of unique items (e.g., {1, 2, 3}, {'a', 'b', 'c’})
EXAMPLE:
unique_numbers = {1, 2, 3, 4}
print(unique_numbers) Output: {1, 2, 3, 4}
5.Boolean type:
•bool: Represents truth values, either True or False
EXAMPLE:
is _valid = True
print(is _valid) Output: True
.
DATATYPES
6.NoneType:
•None: Represents a null or empty value.
EXAMPLE:
empty_ value = None
print(empty _value) Output: None
DATA, EXPRESSIONS, STATEMENTS
Question:
Python program that demo ? instates the usage of various
datatypes?
Program
# Numeric types
x = 42 # int
y = 3.14 # float
print(f"Integer: {x}")
print(f"Float: {y}")
# Sequence types
name = "Alice" # str
numbers = [1, 2, 3, 4] # list
print(f"String: {name}")
print(f"List: {numbers}")
Program
# Mapping type
person = {'name': 'Bob', 'age': 25} # dict
print(f"Dictionary: {person}")
# Set type
unique_numbers = {1, 2, 3, 4} # set
print(f"Set: {unique_numbers}")
Program
# Boolean type
is_valid = True # bool
print(f"Boolean: {is_valid}")
# NoneType
empty_value = None # NoneType
print(f"NoneType: {empty_value}")