Python教程

Python基础学习-05

本文主要是介绍Python基础学习-05,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Python基础学习-05

# Python bool
# compare
print(10 > 9)
print(10 == 9)
print(10 < 9)

a = 100
b = 30
if b > a:
    print("b大于a")
else:
    print("b不大于a")

# assessed value
print(bool("喜羊羊"))
print(bool(20))

x = "灰太狼"
y = "15"
print(bool(x))
print(bool(y))

# bool True
bool("abc")
bool(123)
bool(["apple", "cherry", "banana"])

# bool False
bool(False)
bool(None)
bool(0)
bool("")
bool(())
bool([])
bool({})

# function return bool
def my_function ():
    return True
print(my_function())

if my_function():
    print("YES!")
else:
    print("NO!")

# Verifies that an object belongs to some kind of data
x = 200
print(isinstance(x, int))

# Test
"""
回答下面语句返回值
"""
print(10 > 9)
# True
print(10 == 9)
# False
print(10 < 9)
# False
print(bool("abc"))
# True
print(bool(0))
# False
这篇关于Python基础学习-05的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!