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'
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,164评论 0 10
  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom阅读 7,650评论 0 3
  • 这几天尝试着去学习“外星人入侵”这个项目。刚开始只是跟着敲代码,后来感觉这会进入以前的误区,这样对以后能有什么益处...
    浅诞厘汨栽阅读 1,040评论 0 0
  • 今天我初读拿破仑传,但是刚开始读还是有些看不懂,不过感觉对这本书颇有好感。 拿破仑是很久很久以前的...
    于士淋阅读 3,474评论 0 1
  • 今天周日,假期的第一天,早上在生物钟的作用下,大儿子早早的醒了,睡不着了,我就说你小声读会小白书吧,弟弟还没醒...
    轩轩皓皓阅读 825评论 0 0