zoukankan      html  css  js  c++  java
  • Python学习笔记之基础(二)变量和类型

    1. 创建变量,输出变量

    savings = 100
    print(savings)

    2. 变量运算

    savings = 100
    factor = 1.10
    result = savings * factor ** 7
    
    print(result)

    3. 符串和布尔型变量

    desc = "compound interest"
    profitable = True
    
    print(desc)
    print(profitable)


    4. 查看变量类型

    savings = 100
    factor = 1.1
    desc = "compound interest"
    
    year1 = savings * factor
    
    print(type(savings))
    
    print(type(year1))
    
    print(type(desc))

     

    5. 字符串拼接

    直接用加号就能实现字符串的拼接,或者使用 * 数字  来实现字符串的重叠复制。

    desc = "compound interest"
    doubledesc = desc + desc
    
    print(doubledesc)

     6. 基本类型转换

    基本类型转换函数:int(), float(), bool(), str()

    savings = 100
    result = 100 * 1.10 ** 7
    
    print("I started with $" + str(savings) + " and now have $" + str(result) + ". Awesome!")
    
    pi_string = "3.1415926"
    
    pi_float = float(pi_string)
    
    print(pi_float)

  • 相关阅读:
    .net core在linux下图片中文乱码
    微信公众号开发--.net core接入
    洛谷P3385负环
    洛谷P3387缩点
    洛谷P2312解方程
    洛谷P3366最小生成树
    洛谷P3378堆
    洛谷P2024食物链
    洛谷P2680运输计划
    洛谷P2886牛继电器
  • 原文地址:https://www.cnblogs.com/kevinbi/p/7256047.html
Copyright © 2011-2022 走看看