


Built-in Types - Text Sequence Type str Python 3.11. You can also convert objects of other types into strings using str (). To convert given floating-point number to a string in Python, call str() builtin function and pass the floating-point number as argument to the str(). In case you still wish to replace that single \ with \\ you would then use:ĭirectory = string.replace(r"C:\Users\Josh\Desktop\20130216", "\\", "\\\\") In Python, strings ( str) can be created by enclosing text in single quotes ', double quotes ', and triple quotes ( ''', ''' ). If endptr is NULL, convert the whole string. The conversion is independent of the current locale.

The set of accepted strings corresponds to the set of strings accepted by Python’s float () constructor, except that s must not have leading or trailing whitespace. This is a "raw" string, and very useful in situations where you need to use lots of backslashes such as with regular expression strings. Convert a string s to a double, raising a Python exception on failure. The other option is to notify python that your entire string must NOT use \ as an escape character by pre-pending the string with r If you wish to specify \ then you need to put two \\ in your string. This is because \2 has a special meaning in a python string. With your example string you would notice that when you put "C:\Users\Josh\Desktop\20130216" in the repl you will get "C:\\Users\\Josh\\Desktop\x8130216". What this means that in places where you wish to insert a special character (such as newline), you would use the backslash and another character ( \n for newline) In python \ (backslash) is used as an escape character.
