Python string u "% (word) s"

I am a new Python user and I don’t know some parts when I read the code. So I asked here.

cmd = u"sudo umount %(mountpoint)s >>%(log)s 2>&1"

I know what is %(word)used to replace the use of the last word, such as cmd % {'word':'new word'}, but I do not understand why trailing exists s. and I do not know the value of "u" at the beginning of the line.

+3
source share
4 answers
  • u means this is a Unicode string.
  • s denotes a string.
+1
source

The beginning umeans "Unicode" (i.e. this is a Unicode string). safter each formatting code means interpreting the value as a string, unlike dfor decimal, etc.

. http://docs.python.org/library/stdtypes.html#string-formatting-operations.

+7

u , .

s , . a d, , f, float

+3

s , .

. , 3:

(), .

u , unicode, str.

. Unicode Python, , .

+1

Source: https://habr.com/ru/post/1791907/


All Articles