What gets printed?
namesl = [‘Amir’, ‘Barry’, ‘Chales’, ‘Dao’]
if ‘amir’ in namesl:
print 1
else:
print 2
Answers
Answered by
3
print 2..
Chales', 'Dao'] if 'amir' in names1: print(1) else: print(2)
Chales', 'Dao'] if 'amir' in names1: print(1) else: print(2)1
Chales', 'Dao'] if 'amir' in names1: print(1) else: print(2)12 - correct
Chales', 'Dao'] if 'amir' in names1: print(1) else: print(2)12 - correctAn exception is thrown
Chales', 'Dao'] if 'amir' in names1: print(1) else: print(2)12 - correctAn exception is throwndescription: the in keyword can be used to search for a value in a list, set, or dict. In this case the search fails, because the string value is case sensitive.
Answered by
5
The output of the given program will be as follows:
namesl = ['Amir', 'Barry', 'Chales', 'Dao']
if "amir" in namesl:
print ('1')
else:
print ('2')
Output:
2
- The program checked whether "amir" is present in the list or not.
- In the list capatilized "Amir" is present.
- Therefore, upon checking, instead of printing 1, it printed 2.
Similar questions
Physics,
5 months ago
English,
5 months ago
Computer Science,
10 months ago
Computer Science,
10 months ago