zoukankan      html  css  js  c++  java
  • str( )它让Python将非字符串值表示为字符串


    1
    #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 4 age = 23 5 message = "happy " + age +"rd birthday!" #python无法识别age,所以执行结果报错 6 7 print(message) 8 9 执行结果为: 10 11 C:Users byAppDataLocalProgramsPythonPython37python.exe C:/py3/rumen_shijian/str().py 12 Traceback (most recent call last): 13 File "C:/py3/rumen_shijian/str().py", line 5, in <module> 14 message = "happy " + age +"rd birthday!" 15 TypeError: can only concatenate str (not "int") to str 16 17 进程已结束,退出代码1
     1 #!/usr/bin/env python
     2 # -*- coding:utf-8 -*-
     3 
     4 age = 23
     5 message = "happy " + str(age) +"rd birthday!"     #str()它让Python将非字符串值表示为字符串,所以能打印出age的值2和3
     6 
     7 print(message)
     8 
     9 
    10 
    11 执行结果为:
    12 
    13 
    14 C:Users	byAppDataLocalProgramsPythonPython37python.exe C:/py3/rumen_shijian/str().py
    15 happy 23rd birthday!
    16 
    17 进程已结束,退出代码0
  • 相关阅读:
    学习Tomcat(三)
    TIME_WAIT 优化注意事项
    TIME_WAIT 优化
    TCP(一)
    TCP(二)
    TCP(三)
    5-14 练习题及答案
    5-14 进程池
    5-11 操作系统介绍
    5-8套接字socket
  • 原文地址:https://www.cnblogs.com/wl404/p/7880796.html
Copyright © 2011-2022 走看看