print("hello word")
hello word
#与运算,同为真为真
True and False
False
#非运算,取反
not False
True
1>2
False
1 is 1
True
1 is 2
False
| 操作符 | 解释 |
| - - - |- - -|
| < | 小于 |
###字符串
#字符串加法
line = "hello world "
line_1="xiaojiejei"
line+line_1
'hello world xiaojiejei'
#字符串乘line = "hello world "法
line *3
'hello world hello world hello world '
len(line)
12
id(line)
2390217291760
#返回字符串长度
line="niao"
#id变量的内存地址
id(line)
2390217322672
line = "hello world "
id(line)
2390217341104
import time
time.sleep(1)
| W |E |
|— |:— |
| < | G |
| u
| 4 | 5 |
| — | — :|
| 6 | 7 |
| 6 | 7 |
| 4 | 5 |
| — | — :|
| 6 | 7 |
| 6 | 7 |
切片
line="Wo shi li tao ha ha "
#取前10个字符
line[0:10]
'Wo shi li '
#前10个字符隔一个取一个
line[0:20:2]
'W h itoh a'
#取后十个字符
line[-10:]
#取后第十个字符
line[-10]
#繁转字符
line[::-1]
line[-1]
line="WewDFd"
line.capitalize()
'Wewdfd'
#居中
line.center(20)
' WewDFd '
line.center(20,'%')
'%%%%%%%WewDFd%%%%%%%'
#字符出现次数,计数
line.count("d")
1
#是否以给的字符结尾
line.endswith("f")
False
#是否以给的字符开始
line.startswith("w")
False
line.find("a")
-1
#字符不存在报错
line.index("a")
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-125-9efe1b8680aa> in <module>
1 #字符不存在报错
----> 2 line.index("a")
ValueError: substring not found
#大小写
line.upper()
'WEWDFD'
line.lower()
'wewdfd'
#大小写判断
line.isupper()
False
line.islower()
False
line.istitle()
False
line=" deDff "
#去两端空格
line.strip()
'deDff'
#去右端空格
line.rstrip()
' dedff'
#去左端空格
line.lstrip()
'dedff '
#大小写转换
line.swapcase()
' DEdFF '
###问题:表格怎么生产
###问题:表格怎么生产