0

I am trying to paste/concatenate 2 strings together, however whenever I try and combine the currency د.إ, it is placed behind my 2nd string e.g price.

Below is a minimal example of the problem

currency = 'د.إ'
price = '9.99'

string1 = currency + price
print(string1)
string2 = "".join([currency, price])
print(string2)
string3 = "{}{}".format(currency, price)
print(string3)

Does anyone know how to join them so they are correctly ordered?

tdelaney
  • 73,364
  • 6
  • 83
  • 116
Sharma
  • 178
  • 1
  • 3
  • 15
  • What output do you expect and why? This looks like complicated unicode string handling. The correct way to display this is e.g. د.إ500 , NOT د.إ and then 500. See e.g. https://stackoverflow.com/q/38179359/2442804 – luk2302 Jul 06 '22 at 14:15
  • 1
    I think this is a display issue with right-to-left characters and left-to-right characters in the same string. I don't think it's a concatenation problem. See [Concatenate left-to-right and right-to-left languages (arabic, etc.)](https://stackoverflow.com/questions/29713099/concatenate-left-to-right-and-right-to-left-languages-arabic-etc) and [String concatenation containing Arabic and Western characters](https://stackoverflow.com/questions/6177294/string-concatenation-containing-arabic-and-western-characters/6255490#6255490). – Steven Rumbalski Jul 06 '22 at 14:18
  • You could `print(list(string1))` to see what the string order is. – tdelaney Jul 06 '22 at 14:20
  • I'm not sure if I understand the issue. Why don't you print price + currency? – Artur Gasparyan Jul 06 '22 at 14:25
  • 1
    @StevenRumbalski - But since it would display character by character, I think it should be okay. – tdelaney Jul 06 '22 at 14:25
  • @ArturGasparyan OP ***wants*** currency + price, the currency should be first - but due to the characters it will look like price + currency because the currency is right to left. – luk2302 Jul 06 '22 at 14:26

1 Answers1

-1

Tested in Python 3.9.10 REPL:

>>> currency = 'د.إ'
>>> price = '9.99'
>>> print(currency)
د.إ
>>> print(price)
9.99
>>> print(currency, price)
د.إ 9.99
whiskeyo
  • 873
  • 1
  • 9
  • 19