say
str(q)=hello
str(w)=332
str(e)=nasa
str(r)=21
What should I do in order to print <hello,332,nasa,21>
?
Note that brackets and commas are required
say
str(q)=hello
str(w)=332
str(e)=nasa
str(r)=21
What should I do in order to print <hello,332,nasa,21>
?
Note that brackets and commas are required
Python 2.7.13 (default, Dec 18 2016, 07:03:39)
>>> q = 'hello'
>>> w = 332
>>> e = 'nasa'
>>> r = 21
>>> print('<{}>'.format(','.join(map(str, [q, w, e, r]))))
<hello,332,nasa,21>
This also helps when you have the variables to print already in a list, or a lot of them.
You can add all elements to a list,which will be a more clear method:
myList = ["hello","332","nasa","21"];
myList = ','.join(map(str, myList))
print "<" + myList + ">"
As you can iterate over it in future.
If you are using Python 3, you can use the following format:
print(f'<{q},{w},{e},{r}>')
<hello,332,nasa,21>
Source: https://www.youtube.com/watch?v=bQQqxysLIGE&list=PLlrxD0HtieHhS8VzuMCfQD4uJ9yne1mE6&index=11