# python # Prefer using single quote for char demoA = 'It\'s a demo A.' # Prefer using double quote for string to align with other language demoB = "It\'s a demo B." chinese = "中文"#utf-8 uchinese = u"中文"#unicode
>>> demoC = """ It's a ... demo ... C ... """ >>> demoC " It's a \ndemo \nC\n" >>> r"It\'s demo" "It\\'s demo" >>> type(demoA) <type 'str'> >>> del demoC
1 2 3
// Go var demoA string; demoB := "It's a demoB"
1 2 3 4 5 6 7 8 9 10 11 12 13
// Javascript var demoStr = "demo string" var demoStr1 = 'demo string'// signle quote var demoStr = "demo string"// double quote var demoChar = 'a'// no char type in JS, use sigle character in string to present char var demoPath = "\/home\/kasper"// escape
var demoUnicode = '\u4e2d\u6587'; // unicode '中文'
ES6 - multi-line - `...` ` This is multi-line string `
// go str1 + str2 // string concatination len(s) // get length of string str1[i] // get char from string for i, ch := range str { ... }
1 2 3 4 5 6 7 8 9 10
// Javascript str1 = '\u0041'// or double quota "\u0041" str1 += str2; str.length // string length is attribute. In Java, length() is method str.toUpperCase() str1 === str2 str2[0] // 'H' str2.indexOf('World') // 6 str2.substring(0, 5); // Hello, range not include 5 str2.substring(6); // World
format
1
// java
1 2 3 4 5 6 7 8 9 10 11 12
# python # support as format in C # %[(key)][flags(-(left alignment)/+/#(i.e. #c, #X) etc)][width][.precision]typecode(d/f/s/x etc) # %% uses for '%' escape >>> "%(key)s=%(value)d" % dict(key = "a", value = 10) 'a=10'
# format for container objects: list, dict {field!convertflag:formatspec: [[fill]align][sign][#][0][width][.precision][typecode]}