Python—变量详解

变量赋值

a = 1
b = 2
c = 3
print a, b, c   # 1 2 3
 
a = b = c = 1
print a, b, c   # 1 1 1
 
a, b, c = 1, 2, 3
print a, b, c   # 1 2 3

data = ("monkey", 12, ["Python", "java"])
name, age, language = data
print name, age, language      # monkey 12 ['Python', 'java']

交换两个变量的值

a, b = 1, 2
print a, b      # 1 2
a, b = b, a
print a, b      # 2 1

a, b, c = 1, 2, 3
print a, b, c        # 1 2 3
a, b, c = c, b, a
print a, b, c        # 3 2 1

python中有哪些类型的布尔值是False?

print bool(0)
print bool(-0)
print bool(0.0)
print bool(0.0+0.0j)

print bool(None)
print bool(False)

print bool("")
print bool([])
print bool(())
print bool({})

https://www.runoob.com/python/python-variable-types.html

posted @ 2019-10-03 20:07  刘_love_田  阅读(320)  评论(0编辑  收藏  举报