• python之路-基础篇-002



    【〇】学习环境
    操作系统: Mac OS X 10.10.5
    python: Python 3.5.1 
    IDE:PyCharm4.5
     
    【一】条件语句
      if…elif…else...
    #!/usr/bin/env python3
    name = input("请输入用户名:")
    if name == '用户1':
        print("超级管理员")
    elif name == '用户2':
        print("管理员")
    else:
        print("普通用户")

      结果: 

    请输入用户名:用户1
    超级管理员

     【二】数据类型

    1)整形(INT):整数,如 23,-9,0等

    python3.x中已经将INT数据类型和LONG数据类型合并,全部用INT来表示。

    Python 3.5.1 (v3.5.1:37a07cee5969, Dec  5 2015, 21:12:44) 
    [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    >>> a = 2**64    #计算2的64次幂
    >>> a
    18446744073709551616
    >>> type(a)      #查看a的数据类型
    <class 'int'>
    >>> 
    Python 2.7.10 (default, Jul 14 2015, 19:46:27) 
    [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    >>> a = 2**64    #计算2的64次幂
    >>> a
    18446744073709551616L    
    >>> type(a)      #查看a的数据类型
    <type 'long'>
    >>> 

    2)浮点数(FLOAT):

    实数,如:2.8,-0.223等

    >>> b = 0.2
    >>> type(b)
    <class 'float'>

    3)布尔值:0(False)或者1(True)

    >>> 200 == 200
    True
    >>> 100 == 200
    False
    >>> True
    True
    >>> False
    False
    >>> 

     

    4)字符串

    使用''、""或者''' '''引起来的字符

    >>> 'hello'    #使用单引号
    'hello'
    >>> "hello"    #使用双引号
    'hello'
    >>> '''hello   #使用三引号
    ... world
    ... '''
    'hello
    world
    '
    >>> 

     字符串格式化

    1. %s --> 字符串
    2. %d --> 整数
    3. %f -->  浮点数
    #!/usr/bin/env python3
    name = input("name:")
    age = input("age:")
    job = input("job:")
    
    print("information of " + name + "
    Name:" + name + "
    Age:" + age + "
    Job:" + job)
    
    print("information of %s
    Name:%s
    Age:%s
    Job:%s" % (name, name, age, job))
    
    msg = '''
    Information of %s:
        Name:%s
        Age:%s
        Job:%s
    ''' % (name, name, age, job)
    print(msg)

     结果:

    name:user01
    age:21
    job:iter
    
    information of user01
    Name:user01
    Age:21
    Job:iter
    information of user01
    Name:user01
    Age:21
    Job:iter
    
    Information of user01:
        Name:user01
        Age:21
        Job:iter

     未完待续...

  • 相关阅读:
    [Spring cloud 一步步实现广告系统] 5. 投放系统配置+启动+实体类
    [Spring cloud 一步步实现广告系统] 4. 通用代码模块设计
    [Spring cloud 一步步实现广告系统] 3. 网关路由
    [Spring cloud 一步步实现广告系统] 1. 业务架构分析
    [Spring cloud 一步步实现广告系统] 2. 配置&Eureka服务
    [Java 开发利器Lombok] 常用注解演示
    使用maven快速入门
    [Spring-Cloud-Alibaba] Sentinel 规则持久化
    Java 类加载之匿名类和主类相互依赖问题
    [Spring-Cloud-Alibaba] Sentinel 整合RestTemplate & Feign
  • 原文地址:https://www.cnblogs.com/felo/p/5086938.html
Copyright © 2020-2023  润新知