What will be the output after the following statements? myvar = 5 def printvar(): print(myvar, end ='') printvar() printvar() Options 55 5 5 5 10
Question
What will be the output after the following statements?
myvar = 5 def printvar(): print(myvar, end ='') printvar() printvar() Options 55 5 5 5 10
Solution
The output will be 55.
Here's the step by step explanation:
- The variable
myvaris assigned the value 5. - The function
printvar()is defined to print the value ofmyvarwithout adding a newline at the end (due toend = ''). - The function
printvar()is called twice. - Each call to
printvar()prints the value ofmyvar(which is 5) without a newline, so the output of two calls is 55.
Similar Questions
What will be the output after the following statements?def call(var) : print(var, end ='') call(45)Options5545var4 5
What will be the output after the following statements?def xyz(): a = 56 xyz() print(a)OptionsNameErrora = 56xyz56
What will be the output after the following statements?b = 'Code' a = 'is Life' def pypi(x, y): print('hello %s %s' % (y, x)) pypi(a, b)OptionsCode is Lifehello Codehello is Life Codehello Code is Life
What will be the output of the following Python code?def ct(y): global y y+=2 print(y)ct(5)print("hi")Optionserrorhi77hi
What will be the output of the following Python code snippet?print('%d %s %g you' %(1, 'hello', 4.0))Options1 hello you 4.0Error1 hello 4 you1 4 hello you
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.