new files

This commit is contained in:
Ingy döt Net 2013-04-10 12:38:42 -07:00
parent 3af7344581
commit 86c034bb8b
1364 changed files with 21352 additions and 0 deletions

View file

@ -0,0 +1,5 @@
s1 = "A 'string' literal \n"
s2 = 'You may use any of \' or " as delimiter'
s3 = """This text
goes over several lines
up to the closing triple quote"""

View file

@ -0,0 +1,5 @@
items = ["Smith", "John", "417 Evergreen Av", "Chimichurri", "481-3172"]
joined = ",".join(items)
print joined
# output:
# Smith,John,417 Evergreen Av,Chimichurri,481-3172

View file

@ -0,0 +1,5 @@
line = "Smith,John,417 Evergreen Av,Chimichurri,481-3172"
fields = line.split(',')
print fields
# output:
# ['Smith', 'John', '417 Evergreen Av', 'Chimichurri', '481-3172']

View file

@ -0,0 +1,5 @@
s1 = b"A 'byte string' literal \n"
s2 = b'You may use any of \' or " as delimiter'
s3 = b"""This text
goes over several lines
up to the closing triple quote"""

View file

@ -0,0 +1,2 @@
x = b'abc'
x[0] # evaluates to 97

View file

@ -0,0 +1,3 @@
x = b'abc'
list(x) # evaluates to [97, 98, 99]
bytes([97, 98, 99]) # evaluates to b'abc'

View file

@ -0,0 +1,3 @@
s = "Hello "
t = "world!"
u = s + t # + concatenates

View file

@ -0,0 +1,4 @@
assert "Hello" == 'Hello'
assert '\t' == '\x09'
assert "one" < "two"
assert "two" >= "three"

View file

@ -0,0 +1,2 @@
if x=='': print "Empty string"
if not x: print "Empty string, provided you know x is a string"

View file

@ -0,0 +1,3 @@
txt = "Some text"
txt += '\x07'
# txt refers now to a new string having "Some text\x07"

View file

@ -0,0 +1,6 @@
txt = "Some more text"
assert txt[4] == " "
assert txt[0:4] == "Some"
assert txt[:4] == "Some" # you can omit the starting index if 0
assert txt[5:9] == "more"
assert txt[5:] == "more text" # omitting the second index means "to the end"

View file

@ -0,0 +1,3 @@
txt = "Some more text"
assert txt[-1] == "t"
assert txt[-4:] == "text"

View file

@ -0,0 +1,3 @@
v1 = "hello world"
v2 = v1.replace("l", "L")
print v2 # prints heLLo worLd

View file

@ -0,0 +1,3 @@
v1 = "hello"
v2 = "world"
msg = v1 + " " + v2