python打卡

初学python,认识了如何写python.认识了他有哪写开发环境,然后写了一个小小程序,就是“斐波那契数列”问题。还使用了一些序列的运算符。因为是初学python,若有问题,希望大家及时指出

def fbis(num):
    result=[0,1]
    for i in range(num-2):
        result.append(result[-2]+result[-1])
        return result

    def main():
        result=fbis(10)
        fobj=open('C:\\ZZ_Disc_D\\Temp\\result.txt','w+')
        for i,num in enumerate(result):
            print (u"第%d个数是: %d" % (i,num))
            fobj.write("%d"%num)
            time.sleep(1)
            if_name_=='_main_';
            main()

序列运算符的使用

Python 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> a="hell0, I am Zhanghao"
>>> b=a[1]
>>> b=a[7:13]
>>> print (a[ :13])
hell0, I am Z
>>> print (a[14: ])
anghao
>>> print (a)
hell0, I am Zhanghao
>>> print (a+"! !")         #字符串链接
hell0, I am Zhanghao! !
>>> print ('ABC'*3)        #字符串重复生成
ABCABCABC
>>> print (b+"??")
I am Z??
>>> c=[1, 2, "happy",5]
>>> print (c[1: ])         #打印从第一个到最后一个元素
[2, 'happy', 5]
>>> print (b+c[2])
I am Zhappy
>>>

懂得坚持和拥有一个好奇的心灵
共勉

猜你喜欢

转载自blog.csdn.net/weixin_42373873/article/details/88935137