ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

Python字符串入门

2019-08-19 18:39:20  阅读:190  来源: 互联网

标签:fife 入门 Python s1 repr python print 字符串


# -*- coding: utf-8 -*-
# 开发团队   :pip uninstall python
# 开发人员   :breakmyself
# 开发时间   :2019/8/19  16:05 
# 文件名称   :str.PY
# 开发工具   :PyCharm
#github主页:https://github.com/breakmyself
"""
字符串和转移字符
"""
str1 = 'Charlie'
str2 = "疯狂软件教育"
print(str1)
print(str2)
#转义符  ' str3 = 'I'm a coder' 这样 写不正确,因为包含转义符 ' 需要使用 ""
#使用 “” python会将单引号当成字符串中的内容来操作
str3 = "I'm a coder"
print(str3)
str4 = '"Spring is here , let us jam!",said woodchuck.'
print(str4)
#python 运行使用转义字符,使用反斜线 \ 将字符串中的特殊字符进行转义,
#使用场景:在有单引号和双引号的情况下,必须使用转义字符
str5 = '"we are scared, Let\'s hide in the shade",sys the bird'
print(str5)
#字符串拼接
s1 = "Hello, Charlie"
print(s1)
s2 = "人生苦短 "
s3 = " 我用Python"
s4 = s2 + s3
print(s4)
#repr和字符串:将字符串和数值进行拼接时候可以使用repr
s1 = "这本书的价格是:"
p = 99.8
#直接打印价格会报错,python不允许字符串和数值直接拼接
#print(s1+p)
print(s1+str(p))
#或者使用 repr将数值转换成字符串
print(s1+repr(p))
#str()和 repr()都可以将数值转换成字符串,str是python的内置函数,repr是一个函数
st = "I will play my fife"
print(st)
print(repr(st))
#输出内容
#I will play my fife
#'I will play my fife'

输出内容:

E:\py\venv\Scripts\python.exe E:/py/crazypython/str.py
Charlie
疯狂软件教育
I'm a coder
"Spring is here , let us jam!",said woodchuck.
"we are scared, Let's hide in the shade",sys the bird
Hello, Charlie
人生苦短  我用Python
这本书的价格是:99.8
这本书的价格是:99.8
I will play my fife
'I will play my fife'

 

标签:fife,入门,Python,s1,repr,python,print,字符串
来源: https://blog.csdn.net/u011630259/article/details/99746922

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有