Run the following code and observe the results of str0, type), and id() Create a
ID: 3603690 • Letter: R
Question
Run the following code and observe the results of str0, type), and id() Create a new object called "age" that has a value of 19, and then print the id and type of the new object. birthday-year 1986 2 birthday-month 'April' 3 birthday_day22 Run 5 print('birthday_year --' 6 print( value:', str(birthday_ year)) 7 print(' type:', type(birthday_year)) 8 print(' id:', id(birthday_year)) 9 10 print'nbirthday_month -->') 11 print( value str(birthday_month)) 12 print(' type:', type(birthday_month)) 13 print(' id: ', id(birthday_month)) 15 printnbirthday_day 16 print( value, str(birthday_day)) 17 print(' type: ', type(birthday_day)) 18 print(' id:', id(birthday_day))Explanation / Answer
'''
str() methods returns given parameter as string
type() methods returns the data type of given parameter
id() methods returns the identity of the location of the object in memory which is unique
'''
birthday_year = 1986
birthday_month = 'April'
birthday_day = 22
print('birthday_year -->')
print('value:',str(birthday_year))
print('type:',type(birthday_year))
print('id:',id(birthday_year))
print(' birthday_month -->')
print('value:',str(birthday_month))
print('type:',type(birthday_month))
print('id:',id(birthday_month))
print(' birthday_day -->')
print('value:',str(birthday_day))
print('type:',type(birthday_day))
print('id:',id(birthday_day))
#creating a new object age with value 19
age = 19
print(' Age object -->')
print('type:',type(age))
print('id:',id(age))
"""
sample output
birthday_year -->
value: 1986
type: <class 'int'>
id: 140013649738608
birthday_month -->
value: April
type: <class 'str'>
id: 140013649710808
birthday_day -->
value: 22
type: <class 'int'>
id: 140013693933984
Age object -->
type: <class 'int'>
id: 140013693933888
"""
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.