Watch 1 Star 2 Fork 0

youlixishi / demo-worldLGPL-2.1

Create your Gitee Account
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
http://demoworld.tech 中demo源代码 spread retract

Clone or download
app.py 2.06 KB
Copy Edit Web IDE Raw Blame History
# -*- coding: utf-8 -*-
import sys, json, os, uuid, time
def array_test():
array1 = [] #初始化空数组
array2 = [1,2,3,45]#初始化指定数据的数组
array3 = [1,[1,2,3,4],3,45]#初始化多维数组
array4 = [i for i in range(10)] #初始化范围数据
array1.append(1)#数组追加数据
del array4[0]#删除指定元素
arr = array4
print(array2[-1])#倒数 访问
for x in arr:#遍历
print(x)
for index, value in enumerate(arr):#输出下标号 和 数据
print (index,value)
##转化为tuple
t = tuple(array1)
print(isinstance(t, tuple))
def dic_test():
dic1 = {}
dic2 = {'name': 'francis', 'password':'123456'}
dic3 = {'name':[1,2,3], 'password':{'age':12, 'isok':1}} #初始化复杂字典, 强烈不建议这么保存数据
dic1['name']='francis'##字典赋值
dic1['password']='123456'
del dic1['name']##删除指定键值得 数据
dic = dic1x
#遍历
for key in dic:
is_list = isinstance(dic[key], list)#判断变量类型是否list
print('key='+key +', value type is list='+ str(is_list))#str() 函数 是字符串 转化函数
if is_list:
for x in dic[key]:
print(str(x)+',')
continue
is_dic = isinstance(dic[key], dict)#判断变量类型是否是字典
print('key='+key +', value type is dict='+ str(is_dic))#str() 函数 是字符串 转化函数
if is_dic:
for key1 in dic[key]:
print('key1='+key1+',value='+str(dic[key][key1]))
continue
print('value=' + dic[key])
def tuple_test():#指定长度的数组, 一旦生成长度不能变化
tuple1 = (1,2,3,4,5)#初始化
#print(tuple1[-2])#倒数访问
#for x in tuple1:
# print(x)
tuple2 = tuple1[1:3]#这里 1:3 是 i>=1 and i<3 的区间
for x in tuple2:
print(x)
##转化为list
t = list(tuple1)
print(isinstance(t, list))
if __name__ == '__main__':
tuple_test()

Comment ( 0 )

Sign in for post a comment

1
https://git.oschina.net/youlixishi/demo-world.git
git@git.oschina.net:youlixishi/demo-world.git
youlixishi
demo-world
demo-world
master

Search