Notes

  1. Slice a string
    Notice the left index is included,the right index is excluded .
s = 'HelloPython'
print s[2:5]
# result 'llo'
# From position 2(included) to position 5(excluded)
print s[3:7]
# result 'loPy'
# From position 3(included) to position 7(excluded)
print s[:2]
# An omitted first index defaults to zero
# s[:2] equals s[0:2]
# 'He'
print s[2:]
# An omitted second index defaults to the size of the string being sliced
# s[2:] equals s[2:len(s)]
# lloPython
  1. Function & Details
def square(n):
    """This is used to square a number and return the result"""
    re = n * n
    print '%d squared is %d' %(n,re)
    return re
num = int(raw_input("Show a integer : "))
"""int(String str) can be used to transform a string to integer"""
print square(num)
Show a integer : 4
4 squared is 16
16

3.Delect etc.

m = [1, 3, 5]
n = [1, 3, 5]
p = [1, 3, 5]
print m.pop(1)
# Return 3
print m
# Print [1, 5]

print n.remove(1)
# Print NOTHING
print n
# Print [3, 5]

del(p[1])
# Cannot print the process of del()
print p
# Print [1, 5]

4.Print

for turn in range(4):
    print 'Turn',turn + 1
Turn 1
Turn 2
Turn 3
Turn 4

5.Raw_input

a = raw_input("Enter a number >> ")
if a.isdigit():
    print 'Yes'
    a = int(a)
    print a
else:
    print 'No'

你可能感兴趣的:(Notes)