博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python 学习源码练习(1)
阅读量:7061 次
发布时间:2019-06-28

本文共 1582 字,大约阅读时间需要 5 分钟。

#编译方式,python3 文件名

#!/usr/bin/python3

#print('hello world')

 

mystring = 'hello world'

print (mystring)

 

 

#测试输入

#!\usr\bin\python3

num = input('Please enter an num :')

print ("now Doubling your num %d" % (int(num)*2))

 

#字符串和切片

#!/usr/bin/python3

pystr = 'Python'

iscool = 'is cool'
print ('pystr[0] is %s.' % pystr[0])
print ('pystr[2:5] is %s'% pystr[2:5])

 

 

#!/usr/bin/python3

#if test

count = 1
if count > 1:
    print ("test 1")
elif count == 1 :
    print ("test 2")

 

#while loop test

while count < 3:
    print("now count = %d" % count)
    count += 1

#for loop test
print("I like to use internet for:")
for item in ['e-mail', 'net-surfing', 'homework']:
    print(item,)

    print()

#range test

for eachNum in [0,1,2]:

     print(eachNum)

print('*'*4)

for eachNum in range(3):
     print(eachNum)

print('test for string','*'*4)

foo = 'abs'

for s in foo:
    print(s)

print('test of range and len')

for i in range(len(foo)):

    print (foo[i],'%d'%i)

squared = [x**2 for x in range(4)]
for i in squared:
    print(i)

 

#function test

def addMe2Me(x):
    'apply + operation to argument'
    return (x+x)

print(addMe2Me([2,'4']))

 

#default function param test

#!/usr/bin/python3

def foo(debug=True):
    if debug:
        print('cur in debug mode')
    else:
        print('cur in realse mode')
    print('done')

 foo(False)

 

#class test

#!/usr/bin/python3

class Myfoo(object):
    version = 0.1

    def __init__(self,nm='John Doe'):

        self.name = nm
        print('created a class instance for',nm)
        print('this is a ','test')

    def showname(self):

        print('your name is ', self.name)

    def showverison(self):

        print( self.version)

foo = Myfoo()

 

转载于:https://www.cnblogs.com/honorplus/p/7899390.html

你可能感兴趣的文章
迎接仪式 dp
查看>>
[TJOI2013]循环格 费用流 BZOJ3171
查看>>
Jmeter之Bean shell使用(二)
查看>>
安装Oracle客户端时,检查系统要求时状态为错误的解决办法
查看>>
oracle从入门到精通复习笔记续集之PL/SQL(轻量版)
查看>>
Android百分比布局
查看>>
Android四种Activ“.NET研究”ity的加载模式
查看>>
3G安全提上日程 电信运营商紧寻手机杀毒软件
查看>>
紧急救护受损的Windows系统
查看>>
恶意程序操纵谷歌搜索引擎结果页面 用户需警惕
查看>>
云计算-从基础到应用架构系列-云计算的概念,互联网营销
查看>>
瘦客户端那些事 - 开篇,互联网营销
查看>>
链表递归排序
查看>>
python解析git log后生成页面显示git更新日志信息
查看>>
unittest单元测试框架实现参数化
查看>>
Web版OutLook,利用POP接收邮件服务器邮件
查看>>
经典算法 KMP算法详解
查看>>
sharepoint 2010 安装、卸载和升级沙盒解决方案
查看>>
prog1,2,3
查看>>
手机硬件结构
查看>>