I am having a bit of trouble trying to find an answer to this. I would like to know what the syntax sep=""
and \t
means. I have found some informaion about it but I didn't quite understand what the purpose of using the syntax was. I'm looking for an explanation of what it does and when / why you would use it.
An example of sep=''
being used:
print('Property tax: $', format(tax, ',.2f'), sep='')
This question is related to
python
python-3.x
syntax
separator
sep=''
ignore whiteSpace.
see the code to understand.Without sep=''
from itertools import permutations
s,k = input().split()
for i in list(permutations(sorted(s), int(k))):
print(*i)
output:
HACK 2
A C
A H
A K
C A
C H
C K
H A
H C
H K
K A
K C
K H
using sep=''
The code and output.
from itertools import permutations
s,k = input().split()
for i in list(permutations(sorted(s), int(k))):
print(*i,sep='')
output:
HACK 2
AC
AH
AK
CA
CH
CK
HA
HC
HK
KA
KC
KH
sep='\t'
is often used for Tab-delimited file.
The sep='\t' can be use in many forms, for example if you want to read tab separated value: Example: I have a dataset tsv = tab separated value NOT comma separated value df = pd.read_csv('gapminder.tsv'). when you try to read this, it will give you an error because you have tab separated value not csv. so you need to give read csv a different parameter called sep='\t'.
Now you can read: df = pd.read_csv('gapminder.tsv, sep='\t'), with this you can read the it.
Source: Stackoverflow.com