标签:ble 分片 def 标签 string 小数点 middle nbsp 组成
type()函数
>>> type(3.4)
<class ‘float‘>
>>> type(True)
<class ‘bool‘>
>>> type(3<4)
<class ‘bool‘>
True
False
>>> 4>4
False
>>> 3<4
True
>>> type(2)
<class ‘int‘>
>>> type(2.0)
<class ‘float‘>
a_2
NOfM
_3
4ac
type(4)
type(‘4‘)
type(3<4)
type(4.0)
type(Ture)
>>> a=4
>>> b=3
>>> a/b
1.3333333333333333
>>> a//b
1
>>> a%b
1
>>> a**b
64
>>> a**0.5
2.0
>>> a**-1
0.25
>>> divmod(a,b)
(1, 1)
>>> divmod(b,a)
(0, 3)
>>> 0b1111
>>> 0o7777
>>> 0xfff
>>>
>>> int(True)
1
>>> int(False)
0
>>> int(2.123)
2
>>> int(‘2‘)
2
>>> int(‘-2‘)
-2
>>> -1.2**2
-1.44
>>> (-1.2)**2
1.44
>>> 4.1234e4
41234.0
>>> float(True)
1.0
>>> float(False)
0.0
>>> float(‘2.4‘)
2.4
>>> float(‘1e2‘)
100.0
>>> ‘Snap‘
‘Snap‘
>>> "Crackle"
‘Crackle‘
>>> "‘Nay,‘ said the naysayer."
"‘Nay,‘ said the naysayer."
>>> ‘The rare double quote in captivity: ".‘
‘The rare double quote in captivity: ".‘
>>> ‘A "two by four" is actually 1 1⁄2" × 3
>>> poem = ‘‘‘There was a Young Lady of Norway,
... Who casually sat in a doorway;
... When the door squeezed her flat,
... She exclaimed, "What of that?"
... This courageous Young Lady of Norway.‘‘‘
>>>
s=""
>>> str(98.6)
‘98.6‘
>>> str(1.0e4)
‘10000.0‘
>>> str(True)
‘True‘
>>> ‘Release the kraken! ‘ + ‘At once!‘
‘Release the kraken! At once!‘
>>> a = ‘Duck.‘
>>> b = a
>>> c = ‘Grey Duck!‘
>>> a + b + c
‘Duck.Duck.Grey Duck!‘
>>> start = ‘Na ‘ * 4 + ‘\n‘
>>> middle = ‘Hey ‘ * 3 + ‘\n‘
>>> end = ‘Goodbye.‘
>>> print(start + start + middle + end)
s = "hello",
print(‘he‘ in s)
print(‘aa‘ in s)
print(‘he‘ not in s)
>>> letters = ‘abcdefghijklmnopqrstuvwxyz‘
>>> letters[0]
‘a‘
>>> letters[1]
‘b‘
>>> letters[-1]
‘z‘
>>> letters[-2]
‘y‘
>>> letters[100]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: string index out of range
>>> letters = ‘abcdefghijklmnopqrstuvwxyz‘
>>> letters[:]
‘abcdefghijklmnopqrstuvwxyz‘
>>> letters[20:]
‘uvwxyz‘
>>> letters[10:]
‘klmnopqrstuvwxyz‘
>>> letters[-3:]
‘xyz‘
>>> letters[12:15]
‘mno
>>> letters[18:-3]
‘stuvw‘
>>> letters[-6:-2]
‘uvwx‘
>>> letters[::7]
‘ahov‘
>>> letters[4:20:3]
‘ehknqt‘
>>> letters[19::4]
‘tx‘
>>> letters[:21:5]
‘afkpu‘
>>> letters[::-1]
‘zyxwvutsrqponmlkjihgfedcba‘
提取倒数10 个字符:
提取从倒数第11 到倒数第10 个字符:
从开头提取到偏移量为9 的字符:
从偏移量为7的字符提取到偏移量为17的字符:
>>> len(letters)
26
>>> empty = ""
>>> len(empty)
0
>>> color=‘green,blue,yellow,red,orange,purple,pink‘
>>> color.split(‘,‘)
[‘green‘, ‘blue‘, ‘yellow‘, ‘red‘, ‘orange‘, ‘purple‘, ‘pink‘]
>>> ‘abcdefg‘.split()
[‘abcdefg‘]
>>> ‘a,b,c,d,e,f,g‘.split()
[‘a,b,c,d,e,f,g‘]
>>> ‘a,b,c,d,e,f,g‘.split(‘,‘)
[‘a‘, ‘b‘, ‘c‘, ‘d‘, ‘e‘, ‘f‘, ‘g‘]
>>> ‘a b c d e f g‘.split()
[‘a‘, ‘b‘, ‘c‘, ‘d‘, ‘e‘, ‘f‘, ‘g‘]
>>> n=[‘1‘, ‘2‘, ‘3‘, ‘4‘, ‘5‘, ‘6‘, ‘7‘]
>>> ‘*‘.join(n)
‘1*2*3*4*5*6*7‘
str8 = "Hello Walt Smith"
print(str8.startswith("Hello"))
>>>s=‘abcdedjcjdlslk‘
>>>s1=‘abc‘
>>>s.find(s1)
0
>>>s.find(‘j‘)
6
>>>s.find(‘j‘,2)
6
>>>s.find(‘j‘,7)
8
>>>s.find(‘j‘,10)
-1
str0 = ‘I aM waLt smith‘
print(str4.capitalize()
str5 = "I am walt smith!"
print(str5.title())
str10 = "Hello Walt Smith"
print(str10.lower())
>>> s=" **abc** "
>>> s.strip()
‘**abc**‘
>>> s.strip(‘*‘)
‘ **abc** ‘
>>> s=s.strip()
>>> s
‘**abc**‘
>>> s.strip(‘*‘)
‘abc‘
str0 = ‘hello world hello world‘
str1 = ‘world‘
str2 = ‘waltsmith‘
print( str0.replace(str1, str2) )
print( str0.replace(str1, str2, 1) )
chr(u) x为Unicode编码,返回其对应的字符
ord(x) x为字符,返回其对应的Unicode编码
标签:ble 分片 def 标签 string 小数点 middle nbsp 组成
原文地址:https://www.cnblogs.com/nmucomputer/p/11629681.html