Computer Science
What are three internal key-attributes of a value-variable in Python ? Explain with example.
Answer
The three internal key-attributes of a value-variable in Python are:
- Type
- Value
- Id
For example, consider this:
a = 4
The type of a is int which can be found with the built-in function type() like this:
type(a).
Value can be found using the built-in function print() like this:
print(a)
It will give the output as 4 which is value contained in variable a.
Id is the memory location of the object which can be determined using built-in function id() like this:
id(a)
Related Questions
What are Immutable and Mutable types in Python? List immutable and mutable types of Python.
What will following code print?
str1 = '''Hell o''' str2 = '''Hell\ o''' print(len(str1) > len(str2))
Are these values equal? Why/why not?
- 20 and 20.0
- 20 and int(20)
- str(20) and str(20.0)
- 'a' and "a"
Is it true that if two objects return True for is operator, they will also return True for == operator?