Lichen

tests/string.py

422:4bd1e2112bb6
2016-12-16 Paul Boddie Do not inadvertently create deferred references when testing for objects.
     1 s = "Hello"     2 s += " world!"     3 print s                     # Hello world!     4 print len(s)                # 12     5 print s[:5]                 # Hello     6 print s[5:]                 #  world!     7 print s[1:10:2]             # el ol     8 print s[10:1:-2]            # drwol     9 print s.find("w")           # 6    10 print s.find("w", 7)        # -1    11 print s.find("w", 0, 6)     # -1    12 print s.index("o")          # 4    13     14 try:    15     print s.index("p")      # should raise an exception    16 except ValueError, exc:    17     print 's.index("p"): value is not appropriate', exc.value    18     19 print s.startswith("Hello") # True    20 print s.startswith("world") # False    21 print s.endswith("world!")  # True    22 print s.endswith("Hello")   # False    23     24 s2 = "Hello worlds!"    25 print s2                    # Hello worlds!    26 print len(s2)               # 13    27 print s < s2                # True    28 print s <= s2               # True    29 print s == s2               # False    30 print s != s2               # True    31 print s >= s2               # False    32 print s > s2                # False    33     34 print s[0]                  # H    35 print s[-1]                 # !    36     37 print ord(s[0])             # 72    38     39 try:    40     print ord(s)            # should raise an exception    41 except ValueError, exc:    42     print "ord(s): value is not appropriate", exc.value    43     44 l = ["Hello", "world!"]    45 s3 = " ".join(l)    46 print s3                    # Hello world!    47 print len(s3)               # 12    48     49 s4 = "".join(l)    50 print s4                    # Helloworld!    51 print len(s4)               # 11    52     53 s5 = "--".join(l)    54 print s5                    # Hello--world!    55 print len(s5)               # 13    56     57 print hash(s)    58 print hash(s2)    59 print hash(s3)    60 print hash(s4)    61 print hash(s5)