python范例_if关键字和Python范例

python范例

Python if关键字 (Python if keyword)

if is a keyword (case-sensitive) in python, it is used to define an "if statement" block that executes, if a given condition is true. if keyword is a part of conditional statements in python programming languages and it is used with the various type of if-else conditional statements.

if是python中的一个关键字(区分大小写),如果给定条件为true,则用于定义执行的“ if语句”块。 if关键字是python编程语言中条件语句的一部分,它与各种类型的if-else条件语句一起使用。

Syntax of if keyword

if关键字的语法

    if test_condition:
	    statement(s)

Here, if test_condition is True, then statement(s) will be executed.

在这里,如果test_condition为True ,则将执行语句 。

Example:

例:

    Input:
    num = 0

    # condition
    if num==0:
        print("Yes! ", num, " is equal to 0")

    Output:
    Yes!  0  is equal to 0

if关键字的Python示例 (Python examples of if keyword)

Example 1: Check whether a given number is equal to 0.

示例1:检查给定数字是否等于0。

# python code to demonstrate example of 
# if keyword 

# Check whether a given number is equal to 0

# number 
num = 0

if num==0:
    print("Yes! ", num, " is equal to 0")

Output

输出量

Yes!  0  is equal to 0

Example 2: Check whether a given number is positive, negative or zero (using if keyword only).

示例2:检查给定数字是正数,负数还是零(仅在关键字中使用)。

# python code to demonstrate example of 
# if keyword 

# Check whether a given number is
# positive, negative or zero

# number 
num = 20

if num>0:
    print(num, " is positive")

if num<0:    
        print(num, " is negavtive")

if num==0:
    print(num, " is zero")

Output

输出量

20  is positive	


翻译自: https://www.includehelp.com/python/if-keyword-with-example.aspx

python范例

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值