0
What is the difference between a parenthesis and a bracket in phyton
3 Respostas
+ 3
parenthesis can be used to give some expression more priority (Precedence and Associativity of Operators in Python)
example:-
print(5*2+1) - - > 11
print(5*(2+1)) - - > 15
brackets can be used for accessing an element from list by index and also for slicing string etc.
li = [1,2,3]
print([1]) - - > 2
st = "sololearn"
print(st[3:]) - - > learn
https://www.sololearn.com/discuss/1733735/?ref=app
+ 1
Parantheses are used for two purposes: (1) to control the order of operations in an expression, and (2) to supply parameters to a constructor or method (3) For creating tuples
Where as, Brackets are used to index an array, to create lists and to access individual items...
These are only in the case of python..