赞
踩
Python中的字符串是由一系列字符组成的,可以用单引号或双引号括起来
字符串可以进行各种操作,如拼接、索引、切片等。
- """
- 三引号用于文档注释
- 在文件开头编写的内容
- """
-
- s0 = "hello world"
- s1 = 'hello world'
- s2 = """hello world"""
- s3 = '''hello world'''
- s4 = str(True)
- print(type(s0), type(s1), type(s2), type(s3), type(s4))
-
- s5 = "ddddddddddddddddddddd" \
- "dddddddddddddddddddddddddddd" \
- "dddddddddddddddddddddd" \
- "ddddddddddddddddddddddddddd" \
- "dddddddddddddddsssddddddddsdssss"
-
- print(s5, type(s5))
-
- s6 = "abcddddd" \
- "xyz"
- print(s6)
-
- s7 = "`~!@#$%^&*()_+/*9845631.,,../zzzzhidnneof_"
- print(s7, type(s7))
-
- s8 = "i'm ironman"
- s9 = 'hello "郑州"'
-
- # '可以声明字符串 但是 结合\'就成了一个纯粹的单引号
- s10 = 'hello i\'m ironman'
- s11 = "hello \"郑州\""
- print(s10, s11)
-
-
- s12 = "hello\nworld"
- print(s12)
-
- s13 = "hello\tworld"
- print(s13)
-
- s14 = "hello\bworld"
- print(s14)
-
-
- s15 = "中华人民共和国台湾省"
- for c in s15:
- print(c)
-
- print(len(s15), s15[0], s15[9])
-
- for index in range(10):
- print(index, s15[index])
-
-
-
- # 判断一个字符串是否对称
- # abcdcba 12344321 12345321
-
- # 7
- s = "abcdcba"
- # s[0] s[6]
- # s[1] s[5]
- # s[2] s[4]
- # s[3] s[3]
- for index in range(len(s) // 2):
- if s[index] != s[len(s)-1-index]:
- print("不是对称")
- break
- else:
- print(f"是对称")
-
-
-
-
-
-
-
-
-
-
-
-
-
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。