zoukankan      html  css  js  c++  java
  • 数据类型与变量

    '''
    数据类型和变量:int(整数)、bool(布尔)、float(浮点)、complex(复数)、String(字符串)
    None(空值)、变量
    '''
    #String 字符串
    print("I'm ok")
    print(r'\	\')
    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)
  • 相关阅读:
    Python max() 函数
    Python log10() 函数
    Python log() 函数
    Python fabs() 函数
    Java开源-astar:A 星算法
    9款超绚丽的HTML5/CSS3应用和动画特效
    Java中处理异常的9个最佳实践
    Java泛型
    Android界面性能调优手册
    正确使用Android性能分析工具——TraceView
  • 原文地址:https://www.cnblogs.com/lishch/p/9672119.html
Copyright © 2011-2022 走看看