Identifiers

When assign value to a variable in Python like this

temperature = 98.6

This establish temperature as an identifier and associates it with the object expressed on the right-hand side(98.6) Each identifier is implicitly associated with the memory address of the object to which it refers

x = 5
id(x) # to check x identifier associate with int object 5 memory address on ram

Python is dynamically typed language, meaning it’s identifier can have dynamic type(be any type it want and can be reassign to object with same or different type).

Identifiers do not have type but the object to which it refers has a definite type. Like 5 have int type.

alias is second identifier to an existing object.

temperature = 98.6
original = temperature 
# original is an alias to 5 oject and have same memory address as temperature

Instantiation

Python built-in class

Set

set using Hash table data structure therefore it has a highly optimized method for checking whether a specific element is contained in the set But there are 2 restriction:

  • The first is that the set does not maintain the elements in any particular order meaning we can’t get index of element in set
a = {1,2,3,3}
print(a[1])

# TypeError: 'set' object is not subscriptable
  • The second is that only instances of immutable types can be added to a Python set. It is possible to maintain a set of tuples, but not a set of lists or a set of sets, as lists and sets are mutable.

Equality Operator

is same identity is not different identity == equivalent != not equivalent

a = [1,2]

b = a

c = list(a)

print(a)

print(c)

print(a is b)

print(a is c)

# Output
[1, 2]
[1, 2]
True
False