2020-10-19 21:08:55

This commit is contained in:
wizardforcel
2020-10-19 21:08:55 +08:00
parent 7f63048035
commit ab0caba1f0
140 changed files with 3982 additions and 3982 deletions

View File

@@ -6,26 +6,26 @@
In [1]:
```
```py
s = "hello, world"
print s
```
```
```py
hello, world
```
In [2]:
```
```py
s = 'hello world'
print s
```
```
```py
hello world
```
@@ -36,7 +36,7 @@ hello world
In [3]:
```
```py
s = 'hello ' + 'world'
s
@@ -44,7 +44,7 @@ s
Out[3]:
```
```py
'hello world'
```
@@ -52,14 +52,14 @@ Out[3]:
In [4]:
```
```py
"echo" * 3
```
Out[4]:
```
```py
'echoechoecho'
```
@@ -67,14 +67,14 @@ Out[4]:
In [5]:
```
```py
len(s)
```
Out[5]:
```
```py
11
```
@@ -84,7 +84,7 @@ Out[5]:
跟很多语言一样,**Python**使用以下形式来调用方法:
```
```py
对象.方法(参数)
```
@@ -94,14 +94,14 @@ s.split()将s按照空格包括多个空格制表符`\t`,换行符`\n`
In [6]:
```
```py
line = "1 2 3 4 5"
numbers = line.split()
print numbers
```
```
```py
['1', '2', '3', '4', '5']
```
@@ -110,14 +110,14 @@ s.split(sep)以给定的sep为分隔符对s进行分割。
In [7]:
```
```py
line = "1,2,3,4,5"
numbers = line.split(',')
print numbers
```
```
```py
['1', '2', '3', '4', '5']
```
@@ -128,7 +128,7 @@ print numbers
In [8]:
```
```py
s = ' '
s.join(numbers)
@@ -136,13 +136,13 @@ s.join(numbers)
Out[8]:
```
```py
'1 2 3 4 5'
```
In [9]:
```
```py
s = ','
s.join(numbers)
@@ -150,7 +150,7 @@ s.join(numbers)
Out[9]:
```
```py
'1,2,3,4,5'
```
@@ -160,7 +160,7 @@ s.replace(part1, part2)将字符串s中指定的部分part1替换成想要的部
In [10]:
```
```py
s = "hello world"
s.replace('world', 'python')
@@ -168,7 +168,7 @@ s.replace('world', 'python')
Out[10]:
```
```py
'hello python'
```
@@ -176,14 +176,14 @@ Out[10]:
In [11]:
```
```py
s
```
Out[11]:
```
```py
'hello world'
```
@@ -195,14 +195,14 @@ s.lower()方法返回一个将s中的字母全部小写的新字符串。
In [12]:
```
```py
"hello world".upper()
```
Out[12]:
```
```py
'HELLO WORLD'
```
@@ -210,14 +210,14 @@ Out[12]:
In [13]:
```
```py
s = "HELLO WORLD"
print s.lower()
print s
```
```
```py
hello world
HELLO WORLD
@@ -233,7 +233,7 @@ s.rstrip()返回一个将s结尾的多余空格除去的新字符串。
In [14]:
```
```py
s = " hello world "
s.strip()
@@ -241,7 +241,7 @@ s.strip()
Out[14]:
```
```py
'hello world'
```
@@ -249,40 +249,40 @@ s的值依然不会变化
In [15]:
```
```py
s
```
Out[15]:
```
```py
' hello world '
```
In [16]:
```
```py
s.lstrip()
```
Out[16]:
```
```py
'hello world '
```
In [17]:
```
```py
s.rstrip()
```
Out[17]:
```
```py
' hello world'
```
@@ -292,14 +292,14 @@ Out[17]:
In [18]:
```
```py
dir(s)
```
Out[18]:
```
```py
['__add__',
'__class__',
'__contains__',
@@ -379,14 +379,14 @@ Python 用一对 `"""` 或者 `'''` 来生成多行字符串:
In [19]:
```
```py
a = """hello world.
it is a nice day."""
print a
```
```
```py
hello world.
it is a nice day.
@@ -396,14 +396,14 @@ it is a nice day.
In [20]:
```
```py
a
```
Out[20]:
```
```py
'hello world.\nit is a nice day.'
```
@@ -416,7 +416,7 @@ Out[20]:
In [21]:
```
```py
a = ("hello, world. "
"it's a nice day. "
"my name is xxx")
@@ -426,13 +426,13 @@ a
Out[21]:
```
```py
"hello, world. it's a nice day. my name is xxx"
```
In [22]:
```
```py
a = "hello, world. " \
"it's a nice day. " \
"my name is xxx"
@@ -442,7 +442,7 @@ a
Out[22]:
```
```py
"hello, world. it's a nice day. my name is xxx"
```
@@ -455,27 +455,27 @@ Out[22]:
In [23]:
```
```py
str(1.1 + 2.2)
```
Out[23]:
```
```py
'3.3'
```
In [24]:
```
```py
repr(1.1 + 2.2)
```
Out[24]:
```
```py
'3.3000000000000003'
```
@@ -487,14 +487,14 @@ Out[24]:
In [25]:
```
```py
hex(255)
```
Out[25]:
```
```py
'0xff'
```
@@ -502,14 +502,14 @@ Out[25]:
In [26]:
```
```py
oct(255)
```
Out[26]:
```
```py
'0377'
```
@@ -517,14 +517,14 @@ Out[26]:
In [27]:
```
```py
bin(255)
```
Out[27]:
```
```py
'0b11111111'
```
@@ -532,14 +532,14 @@ Out[27]:
In [28]:
```
```py
int('23')
```
Out[28]:
```
```py
23
```
@@ -547,40 +547,40 @@ Out[28]:
In [29]:
```
```py
int('FF', 16)
```
Out[29]:
```
```py
255
```
In [30]:
```
```py
int('377', 8)
```
Out[30]:
```
```py
255
```
In [31]:
```
```py
int('11111111', 2)
```
Out[31]:
```
```py
255
```
@@ -588,14 +588,14 @@ Out[31]:
In [32]:
```
```py
float('3.5')
```
Out[32]:
```
```py
3.5
```
@@ -607,14 +607,14 @@ Out[32]:
In [33]:
```
```py
'{} {} {}'.format('a', 'b', 'c')
```
Out[33]:
```
```py
'a b c'
```
@@ -622,14 +622,14 @@ Out[33]:
In [34]:
```
```py
'{2} {1} {0}'.format('a', 'b', 'c')
```
Out[34]:
```
```py
'c b a'
```
@@ -637,14 +637,14 @@ Out[34]:
In [35]:
```
```py
'{color} {n} {x}'.format(n=10, x=1.5, color='blue')
```
Out[35]:
```
```py
'blue 10 1.5'
```
@@ -652,14 +652,14 @@ Out[35]:
In [36]:
```
```py
'{color} {0} {x} {1}'.format(10, 'foo', x = 1.5, color='blue')
```
Out[36]:
```
```py
'blue 10 1.5 foo'
```
@@ -667,7 +667,7 @@ Out[36]:
In [37]:
```
```py
from math import pi
'{0:10} {1:10d} {2:10.2f}'.format('foo', 5, 2 * pi)
@@ -676,7 +676,7 @@ from math import pi
Out[37]:
```
```py
'foo 5 6.28'
```
@@ -686,7 +686,7 @@ Out[37]:
In [38]:
```
```py
s = "some numbers:"
x = 1.34
y = 2
@@ -697,13 +697,13 @@ t = "%s %f, %d" % (s, x, y)
In [39]:
```
```py
t
```
Out[39]:
```
```py
'some numbers: 1.340000, 2'
```