+ 1
a=(3+5,) print(a*2).....The output is (8,8) How it come.
Please explain
4 Antworten
+ 4
This code should explain it all.
(When you multiply a string by an integer, Python returns a new string. This new string is the original string, repeated X number of times (where X is the value of the integer))
Same applies to set, list in python.
[CODE]
# tuples
a=(3+5,)
print(a)
print(a*2)
print(a*3)
print(a*4)
# string
print("understood "*3)
# list
l = [1,2,3]
print(l*2)
+ 1
thanks NotAPythonNinja 😇
+ 1
Rajulapudi Aswini,
As a future reference, next time please, don't forget to use proper tags in your question 👍
https://code.sololearn.com/W3uiji9X28C1/?ref=app
+ 1
variable a is a tuple, then we multiply tuple by 2 and our result -tuple (8,8)🙂 it’s the same if we (8,) +(8,) result will be (8,8)