w3resource

Python: Print a variable without spaces between values

Python Basic: Exercise-135 with Solution

Write a Python program to print a variable without spaces between values.

Sample value : x =30
Expected output : Value of x is "30"

Sample Solution-1:

Python Code:

x = 30
print('Value of x is "{}"'.format(x))

Sample Output:

Value of x is "30" 

Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:


Sample Solution-2:

Python Code:

x = 30
print("Value of x is \"%i\"" % x)

Sample Output:

Value of x is "30" 

Sample Solution-3:

Python Code:

x = 30
print("Value of x is "+'\"' + str(x) + '\"')

Sample Output:

Value of x is "30" 

Python Code Editor:

 

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to input two integers in a single line.
Next: Write a Python program to find files and skip directories of a given directory.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

Unpack variables from iterable:

# One can unpack all iterables (tuples, list etc)
>>> a, b, c = 1, 2, 3
>>> a, b, c
(1, 2, 3)

>>> a, b, c = [1, 2, 3]
>>> a, b, c
(1, 2, 3)