zoukankan      html  css  js  c++  java
  • python 1

    type()

    type是检测是什么类型,例如:

    Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] on win32
    Type "help", "copyright", "credits" or "license()" for more information.
    >>> string='nihao'
    >>> print(string)
    nihao
    >>> type(string)
    <class 'str'>

    eval()的功能是“将任意含有数字的字符串转化为有效的数字,进而参与表达式求值运算或者直接返回数字结果,待转化的字符只包含数字字符,不应该有其他的字符。

    例如:

    import math
    shuxue=eval(input("请输入你是的数学成绩:"))
    yuwen=eval(input("请输入你是的语文成绩:"))
    jisuanji=eval(input("请输入你是的计算机成绩:"))
    a=(shuxue+yuwen+jisuanji)/3
    print(a)

    出题:计算一个半径为2的圆的面积

    import math
    r=2
    s=3.14*(r**2)
    print(s)

    出题:输入半径输出其面积

    import math
    r=eval(input("请输入半径"))
    s=3.14*(r**2)
    print(s)

    python提供了一种输出格式化字符串的函数,即string.format()函数,string是预输出的字符串。format()函数可以通过 ”{ }“ 和 ” : “ 来输出各种格式的字符串。”{ }“ 指定了字符串中使用的数据的序号,按照序号用对应的数据代替。

    例如:

    “ { }年,我选修了{ }门课程!”.format(" 2018,5")

  • 相关阅读:
    android 内存泄漏分析
    sublime text3
    Bind Service 不会在后台无限期的一直运行
    uint8_t / uint16_t / uint32_t /uint64_t 是什么数据类型?
    #include < >与#include “ ”
    什么是库?
    gcc编译器
    如何写C语言程序
    ubuntu登陆root用户验证失败
    nginx location匹配顺序及CI框架的nginx配置
  • 原文地址:https://www.cnblogs.com/ainv-123/p/13360597.html
Copyright © 2011-2022 走看看