python字符串转浮点数

In the given example, we are printing different values like integer, float, string and Boolean using print() method in python.

在给定的示例中,我们使用python中的print()方法打印不同的值,例如整数,浮点数,字符串和布尔值。

Program:

程序:

# printing integer value
print(12)
# printing float value
print(12.56)
# printing string value
print("Hello")
# printing boolean value
print(True)

Output

输出量

12
12.56
Hello
True

Arithmetic operations inside the print() on values

在print()中对值进行算术运算

# adding and printing integer value
print(12+30)
# adding and printing float value
print(12.56+12.45)
# adding and printing string value
print("Hello"+"World")
# adding and printing boolean value
print(True+False)

Output

输出量

42
25.009999999999998
HelloWorld
1

Printing different types of variables

打印不同类型的变量

# variable with integer value
a=12
# variable with float value
b=12.56
# variable with string value
c="Hello"
# variable with Boolean value
d=True
# printing all variables
print(a)
print(b)
print(c)
print(d)

Output

输出量

12
12.56
Hello
True

Printing different types of variables along with the messages

打印不同类型的变量以及消息

# variable with integer value
a=12
# variable with float value
b=12.56
# variable with string value
c="Hello"
# variable with Boolean value
d=True
# printing values with messages
print("Integer\t:",a)
print("Float\t:",b)
print("String\t:",c)
print("Boolean\t:",d)

Output

输出量

Integer : 12
Float   : 12.56
String  : Hello
Boolean : True

Printing different types of variables with messages and converting them to string using "str()" function

使用消息打印不同类型的变量,并使用“ str()”函数将其转换为字符串

# variable with integer value
a=12
# variable with float value
b=12.56
# variable with string value
c="Hello"
# variable with Boolean value
d=True
# printing values with messages
print("Integer\t:"+str(a))
print("Float\t:"+str(b))
print("String\t:"+str(c))
print("Boolean\t:"+str(d))

Output

输出量

Integer :12
Float   :12.56
String  :Hello
Boolean :True

翻译自: https://www.includehelp.com/python/printing-different-values-integer-float-string-boolean.aspx

python字符串转浮点数

python字符串转浮点数_Python | 打印不同的值(整数,浮点数,字符串,布尔值)...相关推荐

  1. python打印浮点数_python – 打印整数或带有n位小数的浮点数

    使用Python 3 *,您可以只使用 round(),因为除了舍入浮点数,当应用于整数时,它将始终返回一个int: >>> num = 1.2345 >>> ro ...

  2. python中用于标识字符串的定界符_python学习[第六篇] 数据类型之 字符串一

    数据类型之 字符串一 字符串操作 创建及赋值 x = 'abcde'x= "abcde"x= '''abcde'''x= """abcde" ...

  3. python冒号声明类型_Python 函数参数有冒号 声明后有- 箭头 返回值注释 参数类型注释...

    在python3.7 环境下 函数声明时能在参数后加冒号,如图: 1 def f(ham: str, eggs: str = 'eggs') -> str : 2 print("Ann ...

  4. python两列相乘_Python代码将两列相乘,然后用值创建新列

    我正在编写一个python代码,它首先将分钟数据平均为小时数据.然后我想乘以小时数据中两列中的值,并用乘以的值创建一个新列.我被困在乘法步上了.import pandas as pd import n ...

  5. python整数类型-python基础数据类型一(整数类型和布尔值)

    整型(int) 整型在Python中的关键字用int来表示; 整型在计算机中是用于计算和比较的 在python3中所有的整数都是int类型. 但在python2中如果数据量比较大. 会使用long类型 ...

  6. python列表字典操作_Python 列表(list)、字典(dict)、字符串(string)常用基本操作小结...

    创建列表 sample_list = ['a',1,('a','b')] Python 列表操作 sample_list = ['a','b',0,1,3] 得到列表中的某一个值 value_star ...

  7. python replace函数用法_Python实现的从右到左字符串替换方法示例

    本文实例讲述了Python实现的从右到左字符串替换方法.分享给大家供大家参考,具体如下: 一 . 前言 需要用到,但是发现python没有从右边开始替换的内置方法,默认的replace只是从左边开始, ...

  8. python调用所有函数_python打印所有函数调用以了解脚本

    这是名为player.py的代码.在# player.py def foo(): pass def bar(): foo() def car(): bar() pass car() 像$python ...

  9. python实验二序列_python 学习笔记 二 序列, 列表, 元组, 字符串

    序列 序类是一个集合概念, Pthon包括六种内建序列: 列表, 元组, 字符串, Unicode字符串, buffer对象和xrange对象. 其中, 我们最长用的要数前三个. 通用序列操作 1. ...

最新文章

  1. Coprime Sequence 思维 gcd 删一个数
  2. JVM调优总结(二)-一些概念
  3. 使用webflux提升数据导出效率
  4. mac lion 安装 mysql_mac osx下安装mysql
  5. java解析java源码_JAVA语言-Java源码解析-Stack源码分析
  6. 更新MYSQL生成日历表,支持跨年份 存储过程
  7. Android TextView滚动的两种方案
  8. java基础案例教程试题,Java基础案例教程-中国大学mooc-试题题目及答案
  9. 那些从小不干活的人,不做家务,不做饭的人后来怎么样了呀?
  10. 找不到Share Project(Subversion)_android studio
  11. win10+anaconda3+python3.7+pytorch-cpu安装
  12. 后端研发菜鸟成长记 第一章 入门 之 存活下来
  13. linux多线程编程书籍推荐:linux大牛之路从这几本书开始总结
  14. 我的世界服务器地图软件制作教程,我的世界RPG地图制作教程 利用MC小助手进行制作...
  15. ie8 升级页面html,IE9及以下浏览器升级提示
  16. 计算机毕业设计SSM电影票网上订票系统【附源码数据库】
  17. 新能源汽车电池健康状态及能耗分析
  18. 分布式高可靠:流量控制
  19. 用 javascript 解释 curry
  20. 高仿富途牛牛-组件化(四)-优秀的时钟

热门文章

  1. 小说中场景的功能_《流浪地球》:从小说到电影
  2. html向上浮动的方式,JS 实现Div向上浮动的实现代码
  3. html5画电池状态,HTML5的一个显示电池状态的API简介
  4. php cdata,PHPcdata处理(详细介绍)_PHP教程
  5. 获取Linux内存、cpu、磁盘IO等信息
  6. oracle预定义异常
  7. Poor God Water【矩阵快速幂】
  8. Triangle Counting【数学】
  9. requests库入门09-OAUTH认证
  10. Python的threadpool模块