What is the output of this code print (3 * ‘7’) in Python?

Answer: 777 ( And 777 is a string not integer )

In the expression print(3 * ‘7’)
3 is integer
* is the multiplication operator
‘7’ is string

Rule: When we multiply an integer with a string, we get the same string concatenated by integer times. For example

str1 = "hi" # str1 is string
i = 4 # i is integer

str1 * i will give hihihihi

Let’s see the Python code:

print(3 * '7')
#ouput
# 777
Facebook
Twitter
LinkedIn
Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

ABOUT ME !!
Johan William

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

RECENT POSTS

TEST