python整数转换字符串

Given an integer value and we have to convert the value to the string using str() function.

给定一个整数值,我们必须使用str()函数将该值转换为字符串。

Python code to convert an integer value to the string value

Python代码将整数值转换为字符串值

# Python code to convert an integer value
# to the string value
# integer value
i_value = 12345
# converting to the string value
s_value = str(i_value)
# printing the integer & string values with their types
print("i_value: ", i_value)
print("type(i_value): ", type(i_value))
print("s_value: ", s_value)
print("type(s_value): ", type(s_value))
# another operation by multiplying the value
print("i_value*4: ", i_value*4)
print("s_value*4: ", s_value*4)

Output

输出量

i_value:  12345
type(i_value):  <class 'int'>
s_value:  12345
type(s_value):  <class 'str'>
i_value*4:  49380
s_value*4:  12345123451234512345

Code explanation:

代码说明:

In the above code i_value is an integer variable contains an integer value, we are converting i_value to the string by using str() function and storing the result in s_value variable. For further verification of the types – we are printing the types of both variables with their values and also printing their 4 times multiplied value.

在上面的代码中, i_value是一个包含整数值的整数变量,我们通过使用str()函数将i_value转换为字符串并将结果存储在s_value变量中。 为了进一步验证类型,我们将同时打印两个变量的类型及其值,并打印其四倍的乘积值。

Recommended posts

推荐的帖子

  • Read input as an integer in Python

    在Python中将输入读取为整数

  • Read input as a float in Python

    在Python中以浮点形式读取输入

  • Parse a string to float in Python (float() function)

    解析要在Python中浮动的字符串(float()函数)

  • How do you read from stdin in Python?

    您如何从Python的stdin中读取信息?

  • Asking the user for integer input in Python | Limit the user to input only integer value

    要求用户在Python中输入整数| 限制用户仅输入整数值

  • Asking the user for input until a valid response in Python

    要求用户输入直到Python中的有效响应

  • Input a number in hexadecimal format in Python

    在Python中以十六进制格式输入数字

  • Input a number in octal format in Python

    在Python中以八进制格式输入数字

  • Input a number in binary format in Python

    在Python中以二进制格式输入数字

  • How to get the hexadecimal value of a float number in python?

    如何在python中获取浮点数的十六进制值?

  • Convert a float value to the string using str() function in Python

    使用Python中的str()函数将浮点值转换为字符串

  • Input and Output Operations with Examples in Python

    使用Python中的示例进行输入和输出操作

  • Taking multiple inputs from the user using split() method in Python

    使用Python中的split()方法从用户获取多个输入

  • Fast input / output for competitive programming in Python

    快速输入/输出,可在Python中进行有竞争力的编程

  • Precision handling in Python

    Python中的精确处理

  • Python print() function with end parameter

    带有结束参数的Python print()函数

翻译自: https://www.includehelp.com/python/convert-an-integer-value-to-the-string-using-str-function-in-python.aspx

python整数转换字符串

python整数转换字符串_使用Python中的str()函数将整数值转换为字符串相关推荐

  1. python分钟转换小时_关于python:如何将秒转换为小时,分钟和秒?

    我有一个以秒为单位返回信息的函数,但我需要以小时:分钟:秒存储该信息. 有没有简单的方法可以在Python中将秒转换为这种格式? 可在如何在Python中将H:MM:SS时间字符串转换为秒的方法中找到 ...

  2. python温度转换代码_用python编写一个名为“convert_temp”的温度转换函数

    编写一个名为"convert_temp"的温度转换函数.它应该能够处理华氏到摄氏的转换以及摄氏到华氏的转换. 它必须接受并读取传递给它的两个参数:第一,原始温度的温标(只应使用&q ...

  3. python常用语法和示例_使用Python中的示例进行输入和输出操作

    python常用语法和示例 A Program needs to interact with the user to accomplish the desired task; this is done ...

  4. c++语言转换为字符串函数,C++中整型转换为字符串类型

    本文主要介绍C++语言中,整型转换为字符串类型的方法. 1 使用to_string函数 在c++11标准中,我们可以使用to_string函数,将整型转换为字符串类型. 1.1 to_string函数 ...

  5. python整数转换字符串_Python | 将字符串转换为整数列表

    python整数转换字符串 Given a string with digits and we have to convert the string to its equivalent list of ...

  6. python查询和替换一个文本字符串_【Python】python面试题

    一些Python面试题 1. (1)python下多线程的限制以及多进程中传递参数的方式 python多线程有个全局解释器锁(global interpreter lock),这个锁的意思是任一时间只 ...

  7. python创建一个字典、关键字为只包含字母的字符串_探究Python源码,终于弄懂了字符串驻留技术...

    摘要:在本文中,我们将深入研究 Python 的内部实现,并了解 Python 如何使用一种名为字符串驻留(String Interning)的技术,实现解释器的高性能. 每种编程语言为了表现出色,并 ...

  8. python开发每月工资_做python开发想要月薪20K不会这些怎么行?

    Python(发音:英[?pa?θ?n],美[?pa?θɑ:n]),是一种面向对象.直译式电脑编程语言,也是一种功能强大的通用型语言,已经具有近二十年的发展历史,成熟且稳定.它包含了一组完善而且容易理 ...

  9. python自动化办公读后感_《Python编程快速上手——让繁琐的工作自动化》读书笔记3...

    其实,写这个是为了督促自己看书--然后 --其实没有然后了,人一松懈下来,就--ε=(´ο`*)))唉 第四章 列表 ①列表数据类型 -- 列表是数据类型!!! -- -- 没啥好说的了,要不是看书, ...

最新文章

  1. 既往出现中性粒细胞减少的患者可以重新应用依那西普
  2. 2016河北省职称计算机考试试题及答案,2016年最新河北省职称计算机考试试题及答案概要.doc...
  3. Domino设置多台转发主机地址
  4. @@identity、scope_identity()、IDENT_CURRENT('tablename')函数的区别
  5. 获取go语言官方文档的两个方法
  6. 数据库中间件 MyCAT源码分析:【单库单表】插入【推荐阅读】
  7. 【LeetCode从零单排】No.160 Intersection of Two Linked Lists
  8. NT系统DOS网络命令记录
  9. powercmd注册码
  10. python默认安装位置_如何更改python中pip的默认安装路径
  11. input type类型_设备树下的input子系统
  12. java 对象初始化过程_Java——对象初始化顺序使用详解
  13. struts与spring整合方法copy
  14. [NOIP2009 最优贸易]
  15. 给你自己的博客加个 Markdown
  16. 【CF】438E. The Child and Binary Tree
  17. 匀速运动小车卡尔曼_平衡小车卡尔曼滤波算法使用心得
  18. 【Qt编程】基于Qt的词典开发系列十--国际音标的显示
  19. 一个数根号3怎样用计算机计算,手机计算器怎样打出根号3
  20. Java 中的设计模式详细介绍

热门文章

  1. jq实现前端文件上传
  2. NodeJS中resolve添加地址无效
  3. bind函数polyfill源码解析
  4. CSS清除行内元素之间的HTML空白
  5. 转载 300年前的黑色“巫女”
  6. 机智云小程序启蒙:WebSocket网页控制
  7. 父类作为方法的形参以及父类作为方法返回值
  8. csharp: ODP.NET,System.Data.OracleClient(.net 4.0) and System.Data.OleDb读取Oracle g 11.2.0的区别...
  9. Nginx 使用try_files遇到的问题
  10. express接受get数据