pythonif函数_python 笔记 之 if条件选择 函数的定义 及 格式

# -*- coding: utf-8 -*-

# !/usr/bin/env python

# @Time : 2018/4/8 0008 上午 12:13

# @Author : 陈元

# @Email : abcmeabc@163.com

# @file : Demo9.py

# 函数的定义

def hello(name):

print("hello {0}".format(name))

print("hello world")

for i in range(1,10):

print(i)

# 缩进

# 冒号

def f():

m = " dddddd ff "

print(len(m))

# if 条件判断

# 数据判断 (字符串) 1.是否为空

# if a.strip(): 有事没事strip去一下空格

# d if type(a) == "dict"

d = dict(a=1)

# 不推荐用

# if type(d) == "dict":

# print("{0} is dict".format(d))

# 一般这样使用,isinstance判断类型

if isinstance(d,dict):

print("{0} is dict".format(d)) # 可见用format,方便了许多

# 字典和字符串相加怎么办

print(str(d)+"hello world") #强制类型转换

m = [x for x in range(1,10)]

print(len(d))

# if 条件判断:

# 逻辑操作。。。

# 。。。

age = raw_input("Please input your age:")

# if age>=18:

# if int(age)>=18:

if age.strip():

# print("你输入的年龄不符合要求:")

if age.strip().isdigit(): #isdigit 判断是数字,是数字返回true

if int(age)>=18:

print("你是一个成年人")

else:

print("你还是一个小屁孩!")

else:

print("你输入的不是数字!")

else:

print("你输入的只有空格,你SB吧!")

number = raw_input("input number:")

if number > 0:

print("{0} 是正数。".format(number))

elif number < 0:

print("{0} 是负数。".format(number))

else:

print("输入的是{0}。".format(number))

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值