Python is a dynamically typed programming language, which means that the data type of a variable is determined at runtime based on the value assigned to it. Here are some of the commonly used data types in Python:
x = 5
y = -10
z = 0
a = 45.14
b = -4.5
c = 0.0
p = True
q = False
name = 'Yuvi'
msg = "Hello, World!"
fruits = ['Banana', 'Apple', 'Cherry']
numbers = [1, 2, 3, 4, 5]
person = ('Ram', 28, 'Male')
coordinates = (5.14, -3.5)
letters = {'a', 'b', 'c'}
numbers = {1, 2, 3, 4, 5}
person = {'name': 'Ravi', 'age': 35, 'gender': 'Male'}
grades = {'Suman': 90, 'Kamal': 45, 'Ramesh': 95}
import array
# Create an array of integers
my_array = array.array('i', [1, 2, 3, 4, 5])
# Access elements of the array
print(my_array[0]) # prints 1
print(my_array[2]) # prints 3
import collections
# Define a namedtuple class
Person = collections.namedtuple('Person', ['name', 'age', 'gender'])
# Create a Person object
person = Person('Ravi', 25, 'Male')
# Access fields by name
print(person.name) # prints 'Ravi'
print(person.age) # prints 25
print(person.gender) # prints 'Male'
Advertisement
Advertisement