li = list(range(10))
print(li)
# 切片 [start:end:steps] >= start & < end
print(li[2:5]) # [3, 4, 5]
print(li[:4]) # [0, 1, 2, 3]
print(li[5:]) # [6, 7, 8, 9]
print(li[0:20:3]) # [0, 3, 6, 9]
# 負值怎麼處理?
print(li[5: -2]) # [5, 6, 7]
print(li[9:0:-1]) # [9, 8, 7, 6, 5, 4, 3, 2,1]
print(li[9::-1]) # [9 ... 0]
print(li[::-2]) # [9, 7, 5, 3, 1]
# 切片生成乙個新的物件
print(li) # 還是保持原樣
re_li = li[::-1]
print(re_li)
li = [1, 2, 3, '456', [1, 2, 3], ]
print(type(list))
print(type(li))
# 元素訪問
print(li[0])
print(li[-1]) # li[len(li) - 1]
print(li[-2]) # li[len(li) - 2]
# 查詢元素位置
print(li.index('456'))
print(li.index([1, 2, 3]))
# print(li.index(-1))
# 新增元素
l_a = [1, 2, 3]
l_b = [6, 7, 8]
print(l_a)
#刪除元素
del(l_a[-1]) #刪除最後乙個元素
del(l_a[0]) #刪除第乙個元素
print(l_a)
del(l_a[1]) #刪除第二個元素
print(l_a)
l_a =
if not l_a:
print('empty') # not xx和is none不是一回事
if len(l_a) == 0:
print('empty')
for i in li:
print(i)
for i in range(len(li)):
print(li[i])
t = (1, 2, 3, '456')
print(type(t))
# t[0] = 'a'
del(li[-1]) # del(list[index])
del(li[1])
del(li[-2])
print(li)
d=
for key in d.keys(): #遍歷
print(d[key])
for key, value in d.items(): #遍歷
print(key,value)
print('name' in d) #判斷元素是否在字典裡
a = set([1,2,3,6,5,2,3,6,5,9])
b = set([2,2,6,5,9,8,5,2,4])
print(a)
print(5 in a)
print(10 in a)
print(type(range(10)))
# 平方表
square_table =
for i in range(5000):
for i in range(5):
print(square_table[i])
square_generator = (x * x for x in range(50000))
print(type(square_generator))
for i in range(5):
print(next(square_generator))
def fib(limit):
n, a, b = 0, 0, 1
while n < limit:
yield b
a, b = b, a + b
n += 1
return 'done'
import traceback
f = fib(5)
print(type(f))
print(next(f))
print(next(f))
print(next(f))
print(next(f))
print(next(f))
try:
print(next(f))
except stopiteration:
traceback.print_exc()
for i in fib(5):
print(i)
容器埠對映實現訪問容器
1 從外部訪問容器應用 p 或 p埠對映,p,docker會隨機對映49000 49900的埠到內部容器開放的網落埠 2 對映所有介面位址 多次使用 p可以對映多個埠 3 對映到指定位址的指定埠 4 對映到指定位址的任意埠 5 檢視對映埠配置 docker port name 5000 使用dock...
docker容器之間的訪問
乙個簡單的python web應用,需要訪問redis,web應用與redis應用在不同的容器中,下面實現兩個容器的訪問。from flask import flask from redis import redis import os import socket dockerfile 2 啟動re...
vector容器的初使化
建構函式語法 1.vector 無引數 構造乙個空的vector 2.vector size type num,const type val 數量 num 和值 val 構造乙個初始放入num個值為val的元素的vector 3.vector const vector from vector fro...