菜农Python菜鸟第1天学习笔记之print,def,for,while

本文深入探讨了Python中函数定义及使用方法,包括参数传递、类型检查等,并通过实例展示了for循环、while循环的正常与非正常退出过程,以及在不同数据类型下函数的表现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#! -*- coding:utf-8 -*-
#菜农HotPower@163.com 2019.4.8 于西安雁塔菜地
def func(x,*y):
    print("type=%s,x=%d"%(type(x),x))
    for i in range(len(y)):
        print("type={0},y[{1}]={2}".format(type(y[i]),i,y[i]))
        
           
                
for i in range(1,10,2):
    print(i)
    if(i>=5):
        break#for语句非正常退出
else:#for语句正常退出
    print("for语句正常结束!")
    exit()
print("for语句非正常结束!")


i = 0
while(i < 10):
    print(i)
    if(i == 5):
        break#while语句非正常退出
    i += 1
else:#fwhile语句正常退出
    print("while正常结束")
    exit()
print("while非正常结束")

func(1,[1,"a"],25.8,"A")
print("\n")
func(8,"ascii",250,25.0,0.25e+5)
1
3
5
for语句非正常结束!
0
1
2
3
4
5
while非正常结束
type=<type 'int'>,x=1
type=<type 'list'>,y[0]=[1, 'a']
type=<type 'float'>,y[1]=25.8
type=<type 'str'>,y[2]=A


type=<type 'int'>,x=8
type=<type 'str'>,y[0]=ascii
type=<type 'int'>,y[1]=250
type=<type 'float'>,y[2]=25.0
type=<type 'float'>,y[3]=25000.0

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值