python学习(二十二) String(上)

本文详细介绍了Python中字符串的多种创建方式,包括使用单引号、双引号以及转义字符来包含特殊字符。同时,展示了如何使用内置函数如len()获取字符串长度,lower()和upper()进行大小写转换,以及str()实现数据类型转换。此外,文章还演示了字符串拼接的操作。

 

 

str1 = "This is a 'test'"
print(str1)

str1 = 'This is a "test"'
print(str1)

str1 = "This is a \"test\""
print(str1)

str1 = 'This is a \'test\' '
print(str1)

str1 = "This is a single \
string"
print(str1)

'''
len()
lower()
upper()
str()
'''

print(len("abc"))
print("aAbc".lower())
print("abc".upper())
print("abc" +  str(2))
print("hello" + " " + "world")

result:

C:\Users\FeiLiu\AppData\Local\Programs\Python\Python36\python.exe C:/Users/FeiLiu/PycharmProjects/GetBluePageInfo/src/stringTest.py
This is a 'test'
This is a "test"
This is a "test"
This is a 'test' 
This is a single string
3
aabc
ABC
abc2
hello world

 

转载于:https://www.cnblogs.com/liufei1983/p/9831048.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值