PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 44


How many stars (*) does the snippet print?

Show Answer
Correct Answer: A

The code is erroneous because the subtraction operator '-' is not supported for strings in Python. Only concatenation '+' and repetition '*' are allowed for strings. Therefore, attempting to use the '-' operator with strings will result in a TypeError.

Discussion

8 comments
Sign in to comment
pypaulOption: A
Nov 11, 2020

A is answers. The snippet wiill generate a TypeError

smarty_arseOption: A
Jan 21, 2022

Correct. TypeError will be thrown

macxszOption: A
May 3, 2022

A. the code is erroneous

Noarmy315Option: A
Dec 28, 2021

-(minus) is not supported b/n 'str' and 'str', if +(plus) then it works, ex. s=s+s[2] then '******' six stars

666_mOption: A
May 7, 2022

A. the code is erroneous is correct

SuvabrataOption: A
Jun 6, 2022

A is correct. strings support concatenation. '-' is not supported in strings

ArulkumarOption: A
Apr 15, 2023

For strings, only + ( concatenate ) and * (multiply) is allowed. TypeError will be returned Ans: A

seaverickOption: A
Jan 28, 2024

s='*****' s= s - s[2] #TypeError: unsupported operand type(s) for -: 'str' and 'str' print(s) #For strings, only + ( concatenate ) and * (multiply) is allowed. TypeError will be returned #TypeError: unsupported operand type(s) for -: 'str' and 'str' #Ans: the code is erroneous