+ 2
What if i want output with string + integer?
Example a = 2*4 b = 'this is result:' i want output as this is result:8
7 Antworten
+ 5
If you are using python, you can't concatinate strings and integers. To turn an integer into a string, use the str() function. print(b + str(a))
+ 6
This depends on your language, take python for example, you would need to convert the integer to a string type using the str() function. Your code would look something like this:
a = 2*4
b = 'this is result"
print (b +" " + str(a))
just check for the conversion type for the language
+ 5
You could do print(b, a) as well. Or one of these:
print('%s %d' % (b, a))
print('{} {}'.format(b, a))
print('{0} {1}'.format(b, a))
print('{1} {0}'.format(a, b))
print(f'{b} {a}')
print(__import__('string').Template('$b $a').safe_substitute({x: eval(x) for x in ('a', 'b')})) # <= probably shouldn't use this one
+ 4
What language?
+ 2
Thanks All. String function helps
a = 2*4
b = 'this is result:'
c = print(b + str(a))
+ 1
I didn't understand
0
As it is we can't able to add the string and integer, we need to mention the function str(b) to make the compiler to understand that it is a string not an integer,we do this to avoid run time compilation error. So hence,the correct notation for this output to occur is:.
Print(b+str(a))