string-literals

Windows path in Python

巧了我就是萌 提交于 2019-11-25 23:56:39
问题 What is the best way to represent a Windows directory, for example \"C:\\meshes\\as\" ? I have been trying to modify a script but it never works because I can\'t seem to get the directory right, I assume because of the \'\\\' acting as escape character? 回答1: you can use always: 'C:/mydir' this works both in linux and windows. Other posibility is 'C:\\mydir' if you have problems with some names you can also try raw string literals: r'C:\mydir' however best practice is to use the os.path module

What is the backslash character (\\\\)?

空扰寡人 提交于 2019-11-25 22:47:30
What is the string literal \\ backslash ? What does it do? I have thought about it but I do not understand it. I also read it on wikipedia . When I try to print the following: System.out.println("Mango \\ Nightangle"); the output is: Mango \ Nightangle What is the significance of this string literal? Chandra Sekhar \ is used as for escape sequence in many programming languages, including Java. If you want to go to next line then use \n or \r , for tab use \t likewise to print a \ or " which are special in string literal you have to escape it with another \ which gives us \\ and \" Imagine you

String literals: Where do they go?

夙愿已清 提交于 2019-11-25 22:15:58
问题 I am interested in where string literals get allocated/stored. I did find one intriguing answer here, saying: Defining a string inline actually embeds the data in the program itself and cannot be changed (some compilers allow this by a smart trick, don\'t bother). But, it had to do with C++, not to mention that it says not to bother. I am bothering. =D So my question is where and how is my string literal kept? Why should I not try to alter it? Does the implementation vary by platform? Does

Difference between string object and string literal [duplicate]

风流意气都作罢 提交于 2019-11-25 21:56:48
问题 This question already has answers here : What is the difference between “text” and new String(“text”)? (11 answers) Closed 6 years ago . What is the difference between String str = new String(\"abc\"); and String str = \"abc\"; 回答1: When you use a string literal the string can be interned, but when you use new String("...") you get a new string object. In this example both string literals refer the same object: String a = "abc"; String b = "abc"; System.out.println(a == b); // true Here, 2