数据类型与变量

'''
数据类型和变量:int(整数)、bool(布尔)、float(浮点)、complex(复数)、String(字符串)
None(空值)、变量
'''
#String 字符串
print("I'\m ok")
print(r'\\\t\\')
print('''line
line
line''')
备注:
字符串内部既包含'又包含",可以用转义字符\来标识。
字符\本身也要转义,\\表示的字符就是\。
 r''表示''内部的字符串默认不转义。
 '''...'''的格式表示多行内容。


#bool 布尔值
布尔值可以用and、or和not运算
>>> True and True True >>> True and False False >>> False and False False >>> 5 > 3 and 3 > 1 True


>>> True or True True >>> True or False True >>> False or False False >>> 5 > 3 or 1 > 3 True


>>> not True False >>> not False True >>> not 1 > 2 True
#if : else: 布尔值 
age = 12
if age>=18:
    print('hello man')
else:
    print('hello children')
 
# type() and isinstance()
a,b = 1,0.5
print(type(a), type(b))
print(isinstance(a,int), isinstance(b,float))


'''
type():不会认为子类是一种父类型
isinstance():会认为子类是一种父类型
'''


class Foo(object):
    pass
class Bar(Foo):
    pass
print (type(Foo()) == Foo)
print (type(Bar()) == Foo)
print (isinstance(Bar(), Foo))  


# r:不转义
s1 = 72
s2 = 85
r = (s2-s1)/s1*100
print(('成绩提升了{0:0.2f}%').format(r))
print('成绩提高%0.2f%%' % r)


# 输出
print('hello world')
print('The quick brown fox','jumps over','the lazy dog')
# 输入
name = input('please enter your name:')
print('hello:',name)

 

posted @ 2018-09-18 23:30  酸笋  阅读(194)  评论(0编辑  收藏  举报