Question

What will be printed upon running following code: alist = [3, 50, "Kity", [50, 52, "Rover"],...

What will be printed upon running following code:

alist = [3, 50, "Kity", [50, 52, "Rover"], [ ], 3.14, False, 'a']
print(len(alist[3]))alist = [3, 50, "Kity", [50, 52, "Rover"], [ ], 3.14, False, 'a']
print(len(alist[3]))

8

7

2

an error

3

Select the best reason why the code below returns True, False, False respectively?

a = 256
b = 256
print(id(a) == id(b))

c = 5.1
d = 5.1
print(id(c) == id(d))

x = 257
y = 257
print(id(x) == id(y))

All the numbers (both integers and floating point numbers) are immutable in Python and this has nothing to do with number of references

floating point numbers are mutable in Python and this has nothing to do with number of references

numbers grater than 256 are mutable in Python and this has nothing to do with id function

numbers between -5 and 256 inclusive are immutable in Python and this has nothing to do with id function

Python creates single objects (singletons) for values between -5 and 256 inclusive and this has nothing to do with mutability

As shown in below code the function, getrefcount() in sys module returns the count of all the references to a given object or a value. Please carefully analyze the following code and select all the correct conclusions that you can make:

import sys
print(id(1))
alist = [1,1,1, 500, 500]
print(id(1))
print(id(alist[0]))
print(id(alist[4]))
print(id(500))
print(sys.getrefcount(1))
print(sys.getrefcount(500))

for multiple objects referring to value 1 python creates multiple references to a single value 1

for objects referring to value 1 python creates multiple values 1 and multiple references to those multiple values

for multiple objects referring to value 500 python creates multiple references to a single value 500

for multiple objects referring to value 500 python creates multiple values of 500 and multiple references to those multiple values

Python seems to be using the value 1 a lot: lot more than value 500

Select all the lines of code that give you vowels = ['a', 'e', 'i', 'o', 'u']:

vowels = list("aeiou")

vowels = "a e i o u".split()

vowels = [ letters for letters in "aeiou"]

vowels = [ letters for letters in "abcdefghijklmnopqrstuvwzyz" if letters in "aeiou"]

vowels = "aeiou".split()

Select why the following code return a Typeerror:

t1 = (1,2, "test", 10)
t1[2] = "pass"

Tuples are immutable

Tuples are mutable

Strings are immutable

Strings are mutable

String object does not support item assignment

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1)What will be printed upon running the following code:

print(len(alist[3])) = 3 ([50, 52, "Rover"])

print(len(alist[3])) = 3 ( ([50, 52, "Rover"]))

2)Select all the lines of code that give you vowels = ['a', 'e', 'i', 'o', 'u']:

vowels = list("aeiou")  

vowels = "a e i o u".split()

vowels = [ letters for letters in "aeiou"]

vowels = [ letters for letters in "abcdefghijklmnopqrstuvwzyz" if letters in "aeiou"]

vowels = "aeiou".split()

ANS)) here all lines of codes gives vowels but first 4 lines of codes gives vowels in the form of list ->( ['a', 'e', 'i', 'o', 'u'])

but last one gives vowels in the form of string in a list ->( ['aeiou'])

3)Select why the following code return a Typeerror:
t1 = (1,2, "test", 10)
t1[2] = "pass"

ANS)) tuples are immutable because the tuple itself isn't mutable it doesn't have any methods for changing its content.

Add a comment
Know the answer?
Add Answer to:
What will be printed upon running following code: alist = [3, 50, "Kity", [50, 52, "Rover"],...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT