I have this:
print('abcd'+'_',cariable)
which gives me this:
abcd_ 2021_mc.txt
But i need this : abcd_2021_mc.txt i.e. no space between _ and 2.
Can anybody suggest me on this. it would be of a great HELP !! thanks in Advance :)
I have this:
print('abcd'+'_',cariable)
which gives me this:
abcd_ 2021_mc.txt
But i need this : abcd_2021_mc.txt i.e. no space between _ and 2.
Can anybody suggest me on this. it would be of a great HELP !! thanks in Advance :)
You can control the separator used by print
using the sep
parameter.
>>> print('abcd','2021_mc.txt', sep='')
abcd2021_mc.txt
>>>
If the variable cariable
is a string then you can do string concatenation directly and just do print('abcd'+'_'+cariable)
. That should result in abcd_2021_mc.txt
.
You can use sep
argument for print function.
print("abcd", cariable, sep='_')
I am not sure why you are concatenating 'abcd'
and '_'
when the results are clearly 'abcd_'
.
When you print multiple fields, the default separator is a space. But you can override that. I can only deduce that cariable
is '2021_mc.txt', so:
print('abcd', '_', cariable, sep='') # no space between 'abcd', '_', and cariable
#or:
print('abcd_', cariable, sep='')
#or:
print('abcd' + '_', cariable, sep='')
Update
>>> cariable = '2021_mc.txt'
>>> print('abcd', '_', cariable, sep='') # no space between 'abcd', '_', and cariable
abcd_2021_mc.txt
>>> #or:
>>> print('abcd_', cariable, sep='')
abcd_2021_mc.txt
>>> #or:
>>> print('abcd' + '_', cariable, sep='')
abcd_2021_mc.txt
>>>
Using f-strings:
print(f"abcd_{cariable}")
If you need to have "abcd" and "_" separated:
s = "abcd"
print(f"{s}_{cariable}")