How to print forward slash in python
You need to escape your backslash by preceding it with, yes, another backslash: Show
And for versions prior to Python 3:
The As you can probably guess, See the Python 3 documentation for string literals. On this page: commenting with #, multi-line strings with """ """, printing multiple objects, the backslash "\" as the escape character, '\t', '\n', '\r', and '\\'. Video Tutorial
Video Summary
Learn More
PracticeThere are at least three ways to print I'm hugry. What are they? Try in IDLE shell. There are at least three ways to print Fleas, Adam, Had'em (the shortest
English poem ever written apparently) in three separate lines, using one print() function. What are they? Try in IDLE shell. Explore
How do you do a forward slash in Python?Programming languages, such as Python, treat a backslash (\) as an escape character. For instance, \n represents a line feed, and \t represents a tab. When specifying a path, a forward slash (/) can be used in place of a backslash.
How do you print backslash and forward slash in Python?For completeness: A backslash can also be escaped as a hex sequence: "\x5c" ; or a short Unicode sequence: "\u005c" ; or a long Unicode sequence: "\U0000005c" . All of these will produce a string with a single backslash, which Python will happily report back to you in its canonical representation - '\\' .
How do I print a slash?We have to use a double backslash (\\) to print a backslash (\).
How do you make a string with a slash in Python?To insert characters that are illegal in a string, use an escape character. An escape character is a backslash \ followed by the character you want to insert.
|