首页 文章 精选 留言 我的

精选列表

搜索[基础],共10000篇文章
优秀的个人博客,低调大师

零基础兴趣或者转行学习Python,我们应该如何入门呢?

Python 语言应该如何入门,记得我几年前也碰到过这样的问题,当时网上随便搜了一下饥不择食的找了一些书开始啃起来,结果发现很疑惑,感觉吃力,走了很多弯路。若不得法还会降低初学者的兴趣,现在我就说说自己对python 入门的理解. 学Python和学其他的语言其实是相同的,我给新同事讲课的时候就说学编程和练武功其实是很相似,入门大致这样几步: 找本靠谱的书, 找个靠谱的师傅, 找一个地方开始练习。 学语言也是的:选一本通俗易懂的书,找一个好的视频资料,然后自己装一个IDE工具开始边学变写。下面我具体来讲讲: 1.找一本靠谱的书,难度一定要是入门级别,千万不能太复杂,不要一下子陷进去,会打乱节奏,学东西要循序渐进,不能一口吃个胖子.打个比方,学过java的同学都听过大名鼎鼎的thinking in java,这边书很厚很全,若一上来就学,肯定会吃力,时间长了就会失去兴趣,因此对初学者来说,一定要找一个通熟易懂的,简单的书。入门的书非常关键。 入门的书很多,但是我个人强烈推荐"A Byte of Python",这本书我读了2遍,作者写的思路非常清晰,对每一个知识点讲解的很到位,不多不少,刚刚好,对初学者来说,力道刚刚好。而且是全英文,对提高自己的英语水平,很有帮助. 2.找一个好的视频资源,当然若你周围有Python高手就更好了,可以多交流多请教。视频资源我推荐imooc,当然有人说还有jikexueyuan,网易公开课,这几家我都看过一些,各有千秋,我建议初学者还是选择imooc,他家的Python讲解的很仔细,而且音频的质量比较高,最关键是的可以在web上直接编程练习,都不用自己安装编译器,非常方便。居家旅行必备啊~~ 3.多编写程序,这似乎是废话,但是确实是一句实话。学编程一定要亲身去编写,没有什么捷径.一开始哪怕你把书里面的例子一字不落敲一遍,也好过你只是去看书,而不动手。 而且学Python最好是坚持编,每天抽小半个小时,学一些知识点,不断的坚持.大概快的话几个星期基本就能入门了。 编推荐一个学python的学习qun 227 435 450,无论你是大牛还是小白,是想转行还是想入行都可以来了解一起进步一起学习!裙内有开发工具,很多干货和技术资料分享! 以上就是我对Python入门的感悟,希望对初学者能有一点帮助,能帮到一些人少走一点弯路.也就不枉我大半夜在这里码字了~~

优秀的个人博客,低调大师

Python基础系列-用paramiko写一个简单的ssh终端

版权声明:如需转载,请注明转载地址。 https://blog.csdn.net/oJohnny123/article/details/82144008 #!/usr/bin/python # -*- coding: UTF-8 -*- """ Created by liaoyangyang1 on 2017/11/7. """ import paramiko import sys import socket import select from paramiko.py3compat import u tran = paramiko.Transport(('ip', 22,)) tran.start_client() tran.auth_password('username', 'password') # 打开一个通道 chan = tran.open_session() # 获取一个终端 chan.get_pty() # 激活器 chan.invoke_shell() while True: # 监视用户输入和服务器返回数据 # sys.stdin 处理用户输入 # chan 是之前创建的通道,用于接收服务器返回信息 readable, writeable, error = select.select([chan, sys.stdin, ], [], [], 1) if chan in readable: try: x = u(chan.recv(1024)) if len(x) == 0: print('\r\n*** EOF\r\n') break sys.stdout.write(x) sys.stdout.flush() except socket.timeout: pass if sys.stdin in readable: inp = sys.stdin.readline() chan.sendall(inp) chan.close() tran.close()

优秀的个人博客,低调大师

多线程并发相关的几个重要基础知识点解析

问:volatile 变量和 atomic 变量有什么不同? 答:volatile 变量和 atomic 变量看起来很像,但功能却不一样。 volatile 变量可以确保先行关系,即写操作会发生在后续的读操作之前, 但它并不能保证原子性,也就是说其可以保证变量的可见性与有序性,无法保证原子性。例如用 volatile 修饰 count 变量,则 count++ 操作就不是原子性的。 AtomicInteger 类提供的 atomic 方法可以让这种操作具有原子性,其保证了并发安全的可见性、有序性、原子性三要素。如 getAndIncrement() 方法会原子性的进行增量操作把当前值加一,其它数据类型和引用变量也可以进行相似操作。 问:如果你提交任务时线程池队列已满了则会发会生什么? 答:这取决于线程池队列的实现。 如果线程池使用的是 LinkedBlockingQueue 无界队列,则继续添加任务到阻塞队列中等待执行理论上是不会满的,因为 LinkedBlockingQueue 可以近乎认为是一个无穷大的队列,可以无限存放任务。 如果线程池使用的是有界队列(比如 ArrayBlockingQueue)的话,任务首先会被添加到队列中,当队列满了则会使用拒绝策略 RejectedExecutionHandler 处理满了的任务,默认是 AbortPolicy,我们可以在创建线程池时修改这个策略,譬如是静默忽略还是崩溃等。 问:简单说说并发饥饿与死锁的区别? 答:饥饿是指系统不能保证某个进程的等待时间上界,从而使该进程长时间等待,当等待时间给进程推进和响应带来明显影响时,称发生了进程饥饿。当饥饿到一定程度的进程所赋予的任务即使完成也不再具有实际意义时称该进程被饿死。 死锁是指在多道程序系统中,一组进程中的每一个进程都无限期等待被该组进程中的另一个进程所占有且永远不会释放的资源。 他们的相同点是二者都由于竞争资源而引起。 他们的不同点可以从几个方面来总结: 从进程状态考虑,死锁进程都处于等待状态,忙等待(处于运行或就绪状态)的进程并非处于等待状态,但却可能被饿死; 死锁进程等待永远不会被释放的资源,饿死进程等待会被释放但却不会分配给自己的资源,表现为等待时限没有上界(排队等待或忙式等待); 死锁一定发生了循环等待,而饿死则不然。这也表明通过资源分配图可以检测死锁存在与否,但却不能检测是否有进程饿死; 死锁一定涉及多个进程,而饥饿或被饿死的进程可能只有一个; 在饥饿的情形下,系统中有至少一个进程能正常运行,只是饥饿进程得不到执行机会,而死锁则可能会最终使整个系统陷入死锁并崩溃; 欢迎工作一到五年的Java工程师朋友们加入Java架构开发:744677563 本群提供免费的学习指导 架构资料 以及免费的解答 不懂得问题都可以在本群提出来 之后还会有职业生涯规划以及面试指导

优秀的个人博客,低调大师

Python3 与 NetCore 基础语法对比(List、Tuple、Dict、Set专栏)

Jupyter最新版:https://www.cnblogs.com/dotnetcrazy/p/9155310.html 在线演示:http://nbviewer.jupyter.org/github/lotapp/BaseCode/blob/master/python/notebook/1.POP/3.list_tuple_dict 更新:新增Python可变Tuple、List切片、Set的扩展:https://www.cnblogs.com/dotnetcrazy/p/9155310.html#extend 今天说说List和Tuple以及Dict。POP部分还有一些如Func、IO(也可以放OOP部分说)然后就说说面向对象吧。 先吐槽一下:Python面向对象真心需要规范,不然太容易走火入魔了 -_-!!! 汗,下次再说。。。 对比写作真的比单写累很多,希望大家多捧捧场 ^_^ 进入扩展:https://www.cnblogs.com/dotnetcrazy/p/9155310.html#ext 步入正题: 1.列表相关: Python定义一个列表(列表虽然可以存不同类型,一般我们把相同类型的值存列表里面,不同类型存字典里(key,value)) info_list=[] #空列表 infos_list=["C#","JavaScript"] 遍历和之前一样,for 或者 while 都可以(for扩展:https://www.cnblogs.com/dotnetcrazy/p/9102030.html#forelse) NetCore:var infos_list = new List<object>() { "C#", "JavaScript" }; 遍历可以用foreach,for,while Python列表的添加: # 末尾追加infos_list. append("Java") # 添加一个列表infos_list. extend(infos_list2) # 指定位置插入infos_list. insert(0,"Python") # 插入列表:infos_list .insert(0,temp_list) 看后面的 列表嵌套,是通过下标方式获取,eg: infos_list[0][1] Python在指定位置插入列表是真的插入一个列表进去,C#是把里面的元素挨个插入进去 NetCore:Add,AddRange,Insert,InsertRange (和Python插入列表有些区别) Python列表删除系列: infos_list. pop() #删除最后一个 infos_list. pop(0) #删除指定索引,不存在就报错 infos_list. remove("张三") # remove("")删除指定元素 ,不存在就报错 delinfos_list[1]#删除指定下标元素,不存在就报错 del infos_list#删除集合(集合再访问就不存在了)不同于C#给集合赋null 再过一遍 NetCore:移除指定索引:infos_list.RemoveAt(1); 移除指定值: infos_list.Remove(item);清空列表:infos_list.Clear(); Python修改:(只能通过索引修改) infos_list2[1]="PHP" #只有下标修改一种方式, 不存在则异常 # 想按值修改需要先查下标再修改 eg: infos_list2.index("张三") infos_list2[0]="GO" # infos_list2.index("dnt")# 不存在则异常 # 知识面拓展: https://www.zhihu.com/question/49098374 # 为什么python中不建议在for循环中修改列表? # 由于在遍历的过程中,删除了其中一个元素,导致后面的元素整体前移,导致有个元素成了漏网之鱼。 # 同样的,在遍历过程中,使用插入操作,也会导致类似的错误。这也就是问题里说的无法“跟踪”元素。 # 如果使用while,则可以在面对这样情况的时候灵活应对。 NetCore:基本上和Python一样 Python查询系列:in, not in, index, count if "张三" in names_list: names_list.remove("张三") if "大舅子" not in names_list: names_list.append("大舅子") names_list.index("王二麻子") names_list.count("逆天") NetCore:IndexOf , Count 查找用Contains,其他的先看看,后面会讲 Python排序 num_list. reverse() # 倒序 num_list. sort() # 从小到大排序 num_list. sort(reverse=True) # 从大到小 列表嵌套,获取用下标的方式:num_list[5][1] NetCore:var num_list2 = new List<object>() { 33, 44, 22,new List<object>(){11,55,77} }; 不能像python那样下标操作,可以定义多维数组来支持 num_list2[i][j] (PS,其实这个嵌套不太用,以后都是列表里面套Dict,类似与Json) 2.Tuple 元组 这次先说NetCore吧:(逆天ValueTuple用的比较多,下面案例就是用的这个) 元组系: https://msdn.microsoft.com/zh-cn/library/system.tuple.aspx 值元组: https://msdn.microsoft.com/zh-cn/library/system.valuetuple.aspx C#中元组主要是方便程序员,不用自然可以。比如:当你返回多个值是否还用ref out 或者返回一个list之类的?这些都需要先定义,比较麻烦.元祖在这些场景用的比较多。 先说说基本使用: 初始化: var test_tuple = ("萌萌哒", 1, 3, 5, "加息", "加息"); //这种方式就是valueTuple了(看vscode监视信息) 需要说下的是,取值只能通过 itemxxx来取了,然后就是 valueTuple的值是可以修改的 忽略上面说的(一般不会用的),直接进应用场景: 就说到这了,代码部分附录是有的 Python:用法基本上和列表差不多( 下标和前面说的用法一样,比如test_tuples[-1] 最后一个元素) 定义:一个元素: test_tuple1=(1,) test_tuple=("萌萌哒",1,3,5,"加息","加息") test_tuple.count("加息") test_tuple. index("萌萌哒") #没有find方法 test_tuple. index("加息", 1, 4) #从特定位置查找, 左闭右开区间==>[1,4) 来说说拆包相关的,C#的上面说了,这边来个案例即可: a=(1,2) b=a #把a的引用给b c,d=a #不是把a分别赋值给c和d, 等价于:c=a[0] d=a[1] 来个扩展吧(多维元组): some_tuples=[(2,"萌萌哒"),(4,3)] some_tuples[0] some_tuples[0][1] 3.Dict系列 Python遍历相关: #每一次相当于取一个元组,那可以用之前讲的例子来简化了:c,d=a #等价于:c=a[0] d=a[1] for k,v in infos_dict.items(): print("Key:%s,Value:%s"%(k,v)) NetCore:方式和Python差不多 foreach (KeyValuePair<string, object> kv in infos_dict) { Console.WriteLine($"Key:{kv.Key},Value:{kv.Value}"); } Python增删改系列: 增加、修改:infos_dict["wechat"]="dotnetcrazy" #有就修改,没就添加 删除系列: # 删除 del infos_dict["name"]#不存在就报错 #清空字典内容 infos_dict.clear() # 删除字典 del infos_dict NetCore: 添加:infos_dict.Add("wechat", "lll");infos_dict["wechat1"] = "lll"; 修改: infos_dict["wechat"] = "dotnetcrazy"; 删除: infos_dict.Remove("dog"); //不存在不报错 infos_dict.Clear(); //列表内容清空 Python查询系列:推荐:infos_dict.get("mmd")#查不到不会异常 NetCore:infos_dict["name"] 可以通过ContainsKey(key) 避免异常。看值就 ContainsValue(value) 扩展: 1.多维元组: some_tuples=[(2,"萌萌哒"),(4,3)] some_tuples[0] some_tuples[0][1] 2.运算符扩展:(+,*,in,not in) # 运算符扩展: test_str="www.baidu.com" test_list=[1,"d",5] test_dict={"name":"dnt","wechat":"xxx"} test_list1=[2,4,"n","t",3] # + 合并 (不支持字典) print(test_str+test_str) print(test_list+test_list1) # * 复制 (不支持字典) print(test_str*2) print(test_list*2) # in 是否存在(字典是查key) print("d" in test_str) #True print("d" in test_list) #True print("d" in test_dict) #False print("name" in test_dict) #True # not in 是否不存在(字典是查key) print("z" not in test_str) #True print("z" not in test_list) #True print("z" not in test_dict) #True print("name" not in test_dict) #False 3.内置函数扩展:(len,max,min,del) len(),这个就不说了,用的太多了 max(),求最大值,dict的最大值是比较的key 这个注意一种情况(当然了,你按照之前说的规范,list里面放同一种类型就不会出错了) min(),这个和max一样用 del() or del xxx删完就木有了 #可以先忽略cmp(item1, item2)比较两个值 #是Python2里面有的 cmp(1,2) ==> -1 #cmp在比较字典数据时,先比较键,再比较值 知识扩展: 可变的元组(元组在定义的时候就不能变了,但是可以通过类似这种方式来改变) List切片: Set集合扩展: 更新:(漏了一个删除的方法): 概念再补充下: # dict内部存放的顺序和key放入的顺序是没有关系的# dict的key必须是不可变对象(dict根据key进行hash算法,来计算value的存储位置# 如果每次计算相同的key得出的结果不同,那dict内部就完全混乱了) 用一张图理解一下:(测试结果:元组是可以作为Key的 -_-!) 附录Code: Python:https://github.com/lotapp/BaseCode/tree/master/python/1.POP/3.list_tuple_dict Python List: # 定义一个列表,列表虽然可以存不同类型,一般我们把相同类型的值存列表里面,不同类型存字典里(key,value) infos_list=["C#","JavaScript"]#[] # ########################################################### # # 遍历 for while # for item in infos_list: # print(item) # i=0 # while i<len(infos_list): # print(infos_list[i]) # i+=1 # ########################################################### # # 增加 # # 末尾追加 # infos_list.append("Java") # print(infos_list) # # 指定位置插入 # infos_list.insert(0,"Python") # print(infos_list) # temp_list=["test1","test2"] # infos_list.insert(0,temp_list) # print(infos_list) # # 添加一个列表 # infos_list2=["张三",21]#python里面的列表类似于List<object> # infos_list.extend(infos_list2) # print(infos_list) # # help(infos_list.extend)#可以查看etend方法描述 # ########################################################### # # 删除 # # pop()删除最后一个元素,返回删掉的元素 # # pop(index) 删除指定下标元素 # print(infos_list.pop()) # print(infos_list) # print(infos_list.pop(0)) # # print(infos_list.pop(10)) #不存在就报错 # print(infos_list) # # remove("")删除指定元素 # infos_list.remove("张三") # # infos_list.remove("dnt") #不存在就报错 # print(infos_list) # # del xxx[index] 删除指定下标元素 # del infos_list[1] # print(infos_list) # # del infos_list[10] #不存在就报错 # # del infos_list #删除集合(集合再访问就不存在了) # ########################################################### # # 修改 xxx[index]=xx # # 注意:一般不推荐在for循环里面修改 # print(infos_list2) # infos_list2[1]="PHP" #只有下标修改一种方式 # # infos_list2[3]="GO" #不存在则异常 # print(infos_list2) # # 想按值修改需要先查下标再修改 # infos_list2.index("张三") # infos_list2[0]="GO" # print(infos_list2) # # infos_list2.index("dnt")#不存在则异常 # # 知识面拓展: https://www.zhihu.com/question/49098374 # # 为什么python中不建议在for循环中修改列表? # # 由于在遍历的过程中,删除了其中一个元素,导致后面的元素整体前移,导致有个元素成了漏网之鱼。 # # 同样的,在遍历过程中,使用插入操作,也会导致类似的错误。这也就是问题里说的无法“跟踪”元素。 # # 如果使用while,则可以在面对这样情况的时候灵活应对。 ########################################################### # # 查询 in, not in, index, count # # # for扩展:https://www.cnblogs.com/dotnetcrazy/p/9102030.html#forelse # names_list=["张三","李四","王二麻子"] # # #张三在列表中执行操作 # if "张三" in names_list: # names_list.remove("张三") # print(names_list) # # #查看"大舅子"不在列表中执行操作 # if "大舅子" not in names_list: # names_list.append("大舅子") # print(names_list) # # #查询王二麻子的索引 # print(names_list.index("王二麻子")) # print(names_list.count("大舅子")) # print(names_list.count("逆天")) ########################################################### # # 排序(sort, reverse 逆置) # num_list=[1,3,5,88,7] # #倒序 # num_list.reverse() # print(num_list) # # 从小到大排序 # num_list.sort() # print(num_list) # # 从大到小 # num_list.sort(reverse=True) # print(num_list) # # ########################################################### # # #列表嵌套(列表也是可以嵌套的) # num_list2=[33,44,22] # num_list.append(num_list2) # print(num_list) # # for item in num_list: # # print(item,end="") # print(num_list[5]) # print(num_list[5][1]) # # ########################################################### # # # 引入Null==>None # # a=[1,2,3,4] # # b=[5,6] # # a=a.append(b)#a.append(b)没有返回值 # # print(a)#None View Code Python Tuple: # 只能查询,其他操作和列表差不多(不可变) test_tuple=("萌萌哒",1,3,5,"加息","加息") # count index print(test_tuple.count("加息")) print(test_tuple.index("萌萌哒"))#没有find方法 # 注意是左闭右开区间==>[1,4) # print(test_tuple.index("加息", 1, 4))#查不到报错:ValueError: tuple.index(x): x not in tuple #下标取 print(test_tuple[0]) # 遍历 for item in test_tuple: print(item) i=0 while i<len(test_tuple): print(test_tuple[i]) i+=1 # 扩展: test_tuple1=(1,) #(1)就不是元祖了 test_tuple2=(2) print(type(test_tuple1)) print(type(test_tuple2)) # # ============================================== # 扩展:(后面讲字典遍历的时候会再提一下的) a=(1,2) b=a#把a的引用给b #a里面两个值,直接给左边两个变量赋值了(有点像拆包了) c,d=a #不是把a分别赋值给c和d,等价于:c=a[0] d=a[1] print(a) print(b) print(c) print(d) View Code Python Dict: infos_dict={"name":"dnt","web":"dkill.net"} # # 遍历 # for item in infos_dict.keys(): # print(item) # #注意,如果你直接对infos遍历,其实只是遍历keys # for item in infos_dict: # print(item) # for item in infos_dict.values(): # print(item) # for item in infos_dict.items(): # print("Key:%s,Value:%s"%(item[0],item[1])) # #每一次相当于取一个元组,那可以用之前讲的例子来简化了:c,d=a #等价于:c=a[0] d=a[1] # for k,v in infos_dict.items(): # print("Key:%s,Value:%s"%(k,v)) # # 增加 修改 (有就修改,没就添加) # # 添加 # infos_dict["wechat"]="lll" # print(infos_dict) # # 修改 # infos_dict["wechat"]="dotnetcrazy" # print(infos_dict) # # 删除 # del infos_dict["name"] # del infos_dict["dog"] #不存在就报错 # print(infos_dict) # #清空字典内容 # infos_dict.clear() # print(infos_dict) # # 删除字典 # del infos_dict # 查询 infos_dict["name"] # infos_dict["mmd"] #查不到就异常 infos_dict.get("name") infos_dict.get("mmd")#查不到不会异常 # 查看帮助 # help(infos_dict) len(infos_dict) #有几对key,value # infos_dict.has_key("name") #这个是python2里面的 View Code NetCore:https://github.com/lotapp/BaseCode/tree/master/netcore/1_POP NetCore List: // using System; // using System.Collections.Generic; // using System.Linq; // namespace aibaseConsole // { // public static class Program // { // private static void Main() // { // #region List // //# 定义一个列表 // // # infos_list=["C#","JavaScript"]#[] // var infos_list = new List<object>() { "C#", "JavaScript" }; // // var infos_list2 = new List<object>() { "张三", 21 }; // // // # ########################################################### // // // # # 遍历 for while // // // # for item in infos_list: // // // # print(item) // // foreach (var item in infos_list) // // { // // System.Console.WriteLine(item); // // } // // for (int i = 0; i < infos_list.Count; i++) // // { // // System.Console.WriteLine(infos_list[i]); // // } // // // # i=0 // // // # while i<len(infos_list): // // // # print(infos_list[i]) // // // # i+=1 // // int j=0; // // while(j<infos_list.Count){ // // Console.WriteLine(infos_list[j++]); // // } // // // # ########################################################### // // // # # 增加 // // // # # 末尾追加 // // // # infos_list.append("Java") // // // # print(infos_list) // // DivPrintList(infos_list); // // infos_list.Add("Java"); // // DivPrintList(infos_list); // // // # # 指定位置插入 // // // # infos_list.insert(0,"Python") // // // # print(infos_list) // // infos_list.Insert(0,"Python"); // // DivPrintList(infos_list); // // // # # 添加一个列表 // // // # infos_list2=["张三",21]#python里面的列表类似于List<object> // // // # infos_list.extend(infos_list2) // // // # print(infos_list) // // infos_list.AddRange(infos_list2); // // DivPrintList(infos_list); // // /*C#有insertRange方法 */ // // DivPrintList(infos_list2,"List2原来的列表:"); // // infos_list2.InsertRange(0,infos_list); // // DivPrintList(infos_list2,"List2变化后列表:"); // // // # # help(infos_list.extend)#可以查看etend方法描述 // // // # ########################################################### // // // # # 删除 // // // # # pop()删除最后一个元素,返回删掉的元素 // // // # # pop(index) 删除指定下标元素 // // // # print(infos_list.pop()) // // // # print(infos_list) // // // # print(infos_list.pop(1)) // // // # # print(infos_list.pop(10)) #不存在就报错 // // // # print(infos_list) // // // # # remove("")删除指定元素 // // // # infos_list.remove("张三") // // // # # infos_list.remove("dnt") #不存在就报错 // // // # print(infos_list) // // // # # del xxx[index] 删除指定下标元素 // // // # del infos_list[1] // // // # print(infos_list) // // // # # del infos_list[10] #不存在就报错 // // // # del infos_list #删除集合(集合再访问就不存在了) // // DivPrintList(infos_list); // // infos_list.RemoveAt(1); // // // infos_list.RemoveAt(10);//不存在则报错 // // // infos_list.RemoveRange(0,1); //可以移除多个 // // DivPrintList(infos_list); // // infos_list.Remove("我家在东北吗?"); //移除指定item,不存在不会报错 // // DivPrintList(infos_list,"清空前:"); // // infos_list.Clear();//清空列表 // // DivPrintList(infos_list,"清空后:"); // // // # ########################################################### // // // # # 修改 xxx[index]=xx // // // # # 注意:一般不推荐在for循环里面修改 // // // # print(infos_list2) // // // # infos_list2[1]="PHP" #只有下标修改一种方式 // // // # # infos_list2[3]="GO" #不存在则异常 // // // # print(infos_list2) // // DivPrintList(infos_list2); // // infos_list2[1] = "PHP"; // // // infos_list2[3]="GO"; //不存在则异常 // // DivPrintList(infos_list2); // // // # # 想按值修改需要先查下标再修改 // // // # infos_list2.index("张三") // // // # infos_list2[0]="GO" // // // # print(infos_list2) // // // # # infos_list2.index("dnt")#不存在则异常 // // int index = infos_list2.IndexOf("张三"); // // infos_list2[index] = "GO"; // // DivPrintList(infos_list2); // // infos_list2.IndexOf("dnt");//不存在返回-1 // // // ########################################################### // // // # 查询 in, not in, index, count // // // # # for扩展:https://www.cnblogs.com/dotnetcrazy/p/9102030.html#forelse // // // # names_list=["张三","李四","王二麻子"] // // var names_list=new List<string>(){"张三","李四","王二麻子"}; // // // Console.WriteLine(names_list.Find(i=>i=="张三")); // // // Console.WriteLine(names_list.FirstOrDefault(i=>i=="张三")); // // Console.WriteLine(names_list.Exists(i=>i=="张三")); // // System.Console.WriteLine(names_list.Contains("张三")); // // // # #张三在列表中执行操作 // // // # if "张三" in names_list: // // // # names_list.remove("张三") // // // # else: // // // # print(names_list) // // // # #查看"大舅子"不在列表中执行操作 // // // # if "大舅子" not in names_list: // // // # names_list.append("大舅子") // // // # else: // // // # print(names_list) // // // # #查询王二麻子的索引 // // // # print(names_list.index("王二麻子")) // // // names_list.IndexOf("王二麻子"); // // // # print(names_list.count("大舅子")) // // // # print(names_list.count("逆天")) // // // Console.WriteLine(names_list.Count); // // // ########################################################### // // // # # 排序(sort, reverse 逆置) // // // # num_list=[1,3,5,88,7] // // var num_list = new List<object>() { 1, 3, 5, 88, 7 }; // // // # #倒序 // // // # num_list.reverse() // // // # print(num_list) // // num_list.Reverse(); // // DivPrintList(num_list); // // // # # 从小到大排序 // // // # num_list.sort() // // // # print(num_list) // // num_list.Sort(); // // DivPrintList(num_list); // // // # # 从大到小 // // // # num_list.sort(reverse=True) // // // # print(num_list) // // num_list.Sort(); // // num_list.Reverse(); // // DivPrintList(num_list); // // // # ########################################################### // // // # #列表嵌套(列表也是可以嵌套的) // // // # num_list2=[33,44,22] // // // # num_list.append(num_list2) // // // # print(num_list) // // var num_list2 = new List<object>() { 33, 44, 22,new List<object>(){11,55,77} }; // // DivPrintList(num_list2);//可以定义多维数组来支持 num_list2[i][j] // // // # for item in num_list: // // // # print(item) // // // # ########################################################### // // // # # 引入Null==>None // // // # a=[1,2,3,4] // // // # b=[5,6] // // // # a=a.append(b)#a.append(b)没有返回值 // // // # print(a)#None // #endregion // // Console.Read(); // } // private static void DivPrintList(List<object> list, string say = "") // { // Console.WriteLine($"\n{say}"); // foreach (var item in list) // { // System.Console.Write($"{item} "); // } // } // } // } View Code NetCore Tuple: // using System; // namespace aibaseConsole // { // public static class Program // { // private static void Main() // { // #region Tuple // // C#中元组主要是方便程序员,不用自然可以. // // 元祖系:https://msdn.microsoft.com/zh-cn/library/system.tuple.aspx // // 值元组:https://msdn.microsoft.com/zh-cn/library/system.valuetuple.aspx // // 比如:当你返回多个值是否还用ref out 或者返回一个list之类的? // // 这些都需要先定义,比较麻烦.元祖在一些场景用的比较多 eg: // // 初始化 // // var test_tuple = ("萌萌哒", 1, 3, 5, "加息", "加息"); //这种方式就是valueTuple了 // // test_tuple.Item1 = "ddd";//可以修改值 // // test_tuple.GetType(); // // test_tuple.itemxxx //获取值只能通过itemxxx // var result = GetCityAndTel(); //支持async/await模式 // var city = result.city; // var tel = result.tel; // // 拆包方式: // var (city1, tel1) = GetCityAndTel(); // #endregion // // Console.Read(); // } // // public static (string city, string tel) GetCityAndTel() // // { // // return ("北京", "110"); // // } // // 简化写法 // public static (string city, string tel) GetCityAndTel() => ("北京", "110"); // } // } View Code NetCore Dict: using System; using System.Collections.Generic; namespace aibaseConsole { public static class Program { private static void Main() { #region Dict // infos_dict={"name":"dnt","web":"dkill.net"} // # # 遍历 // # for item in infos_dict.keys(): // # print(item) // # for item in infos_dict.values(): // # print(item) // # for item in infos_dict.items(): // # print("Key:%s,Value:%s"%(item[0],item[1])) // # #每一次相当于取一个元组,那可以用之前讲的例子来简化了:c,d=a #等价于:c=a[0] d=a[1] // # for k,v in infos_dict.items(): // # print("Key:%s,Value:%s"%(k,v)) var infos_dict = new Dictionary<string, object>{ {"name","dnt"}, {"web","dkill.net"} }; // foreach (var item in infos_dict.Keys) // { // System.Console.WriteLine(item); // } // foreach (var item in infos_dict.Values) // { // System.Console.WriteLine(item); // } // foreach (KeyValuePair<string, object> kv in infos_dict) // { // // System.Console.WriteLine("Key:%s,Value:%s",(kv.Key,kv.Value)); // System.Console.WriteLine($"Key:{kv.Key},Value:{kv.Value}"); // } // // # # 增加 修改 (有就修改,没就添加) // // # # 添加 // // # infos_dict["wechat"]="lll" // // # print(infos_dict) // infos_dict.Add("wechat", "lll"); // infos_dict["wechat1"] = "lll"; // // # # 修改 // // # infos_dict["wechat"]="dotnetcrazy" // // # print(infos_dict) // infos_dict["wechat"] = "dotnetcrazy"; // // # # 删除 // // # del infos_dict["name"] // // # del infos_dict["dog"] #不存在就报错 // // # print(infos_dict) // infos_dict.Remove("name"); // infos_dict.Remove("dog"); // // # #清空列表内容 // // # infos_dict.clear() // // # print(infos_dict) // infos_dict.Clear(); // // # # 删除列表 // // # del infos_dict // # 查询 // infos_dict["name"] // infos_dict["mmd"] #查不到就异常 // infos_dict.get("name") // infos_dict.get("mmd")#查不到不会异常 Console.WriteLine(infos_dict["name"]); // Console.WriteLine(infos_dict["mmd"]); //#查不到就异常 // 先看看有没有 ContainsKey(key),看值就 ContainsValue(value) if (infos_dict.ContainsKey("mmd")) Console.WriteLine(infos_dict["mmd"]); // # 查看帮助 // help(infos_dict) // len(infos_dict) #有几对key,value Console.WriteLine(infos_dict.Count); #endregion // Console.Read(); } } } View Code 作者: 毒逆天 出处: https://www.cnblogs.com/dotnetcrazy 打赏: 18i4JpL6g54yAPAefdtgqwRrZ43YJwAV5z 本文版权归作者和博客园共有。欢迎转载,但必须保留此段声明,且在文章页面明显位置给出原文连接!

优秀的个人博客,低调大师

03.Java基础(线程池和Callable<T>)

在以往的工作中,创建线程通常我们关注的都是Thread或者Runnable为主,其实忽略了另外一个比较有用的创建线程的方式,就是Callable接口,下边是Callable配合线程池实现异步任务 import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; public class CallableDemo { public static void main(String[] args) throws InterruptedException, ExecutionException { ExecutorService pool = Executors.newCachedThreadPool(); Future<Object> future = pool.submit(new MyCallable()); //通过get方法获取执行结果,该方法会阻塞直到任务返回结果 Object obj = future.get(); System.out.println(obj.toString()); } } class MyCallable implements Callable<Object>{ @Override public Object call() throws Exception { System.out.println("执行callable3"); return "right"; } } 在Java中,创建线程一般有两种方式,一种是继承Thread类,一种是实现Runnable接口。然而,这两种方式的缺点是在线程任务执行结束后,无法获取执行结果。我们一般只能采用共享变量或共享存储区以及线程通信的方式实现获得任务结果的目的。 不过,Java中,也提供了使用Callable和Future来实现获取任务结果的操作。Callable用来执行任务,产生结果,而Future用来获得结果。 可以看到,与Runnable接口不同之处在于,call方法带有泛型返回值V。 我们通过简单的例子来体会使用Callable和Future来获取任务结果的用法。 假设我们现在有一个任务,要计算出1-10000之间的所有数字的和,为了提升计算速度,我们使用两个线程,第一个线程计算1-5000的和,另外有一个线程计算5001-10000之间的数字的和。为了更好的展示效果,让每个线程在计算过程中休眠5s。 示例程序来自网友: import java.util.ArrayList; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; public class TestMain{ public static void main(String[] args) throws InterruptedException, ExecutionException { ExecutorService executor = Executors.newCachedThreadPool(); ArrayList<Future<Integer>> resultList = new ArrayList<>(); //创建并提交任务1 AddNumberTask task1 = new AddNumberTask(1, 5000); Future<Integer> future1 = executor.submit(task1); resultList.add(future1); //创建并提交任务2 AddNumberTask task2 = new AddNumberTask(5001, 10000); Future<Integer> future2 = executor.submit(task2); resultList.add(future2); executor.shutdown(); int total = 0; for(Future<Integer> future : resultList){ while(true){ if(future.isDone() && !future.isCancelled()){ int sum = future.get(); total += sum; break; } else{ Thread.sleep(100); } } } System.out.println("total sum is " + total); } } class AddNumberTask implements Callable<Integer>{ private int start; private int end; public AddNumberTask(int start, int end) { // TODO Auto-generated constructor stub this.start = start; this.end = end; } @Override public Integer call() throws Exception { // TODO Auto-generated method stub int totalSum = 0; for(int i = start; i <= end; i++){ totalSum += i; } Thread.sleep(5000); return totalSum; } }

优秀的个人博客,低调大师

java基础学习_常用类01_Object类_day11总结

==========================================================================================================================================================涉及的知识点有: 1:Eclipse的概述和使用(掌握) 2:API的概述(了解) 3:Object类的概述和使用握) (1)Object类的概述 (2)Object类的构造方法 (3)要掌握的Object类的方法(掌握) A:public String toString() B:public boolean eauals(Object obj) (4)要了解的Object类的方法 A:public int hashCode() B:public final Class getClass() C:protected void finalize() D:protected Object clone() (5)两个注意问题==========================================================================================================================================================1:Eclipse的概述和使用(掌握)-----------------------------------------------------------------------------2:API的概述(了解) (1) API(Application Programming Interface,应用程序编程接口)是一些预先定义的函数。 目的是:提供应用程序与开发人员基于某软件或硬件的以访问一组例程的能力,而又无需访问源码,或无需理解内部工作机制的细节。 (2)Java API就是Java提供给我们使用的类(也即就是JDK提供给我们的一些提高编程效率的java类), 这些类将底层的实现封装了起来,我们不需要关心这些类是如何实现的,只需要学习这些类如何使用。 我们可以通过查询帮助文档(.chm文件)来了解Java提供的API如何使用。 例如:JDK_API_9.0_zh_CN.CHM JDK_API_1.6_zh_CN.CHM 1.6版本是最常用的版本,是由之前未被Oracle收购的SUN公司为我们中国程序猿写的。给SUN打call!!!-----------------------------------------------------------------------------3:Object类(掌握) (1)Object类的概述 Object n 物体;东西;对象 从JDK1.0版本开始。 Object是类层次结构的根类,所有的类都直接或者间接的继承自Object类。所有对象(包括数组)都实现了这个类的方法。 (2)Object类的构造方法 public Object() {} 有且只有一个,并且是无参构造。 这其实就是理解当时我们说过的:子类的构造方法默认访问的是父类的无参构造。--------------------------------------- (3)要掌握的Object类的方法(掌握) A:public String toString() 返回对象的字符串表示,默认是由类的全路径+@+哈希值的十六进制表示。 结果应该是一个简明扼要的表达,容易让人阅读。 上面的表示其实是没有意义的,建议一般子类都会重写该方法。 没有重写该方法前: Student s = new Student(); System.out.println(s.toString()); // cn.itcast_02.Student@424c0bc4 System.out.println(s.getClass().getName() + '@' + Integer.toHexString(s.hashCode())); // cn.itcast_02.Student@424c0bc4 这两个是等价的。 因为当我们编写了很多类的时候,经常在程序运行时要查看对象中各个属性的值,就要重写toString()方法, 那么如何快速的生成toString()方法呢?过程我也讲解过了,基本要求就是要求信息简单明了。 但是最终还是自动生成。 重写该方法后: 在ecplise中,若直接输出一个对象的名称,其实就是调用该对象的toString()方法。示例如下: Student s = new Student(); System.out.println(s.toString()); // Student [name=null, age=0] System.out.println(s); // Student [name=null, age=0] 这两个也是等价的。 Integer类下的一个静态方法: public static String toHexString(int i) 把一个整数转成一个十六进制表示的字符串--------------------------------------- B:public boolean eauals(Object obj) 比较两个对象是否相同(相等)。默认情况下,比较的是地址值是否相同。 而比较地址值是没有意义的,所以,一般子类也会重写该方法。 重写的代码优化:提高效率,提高程序的健壮性。 怎么重写呢?答:一般都是用来比较对象的成员变量值是否相同。 重写过程,我也详细的讲解和分析了。 但是最终还是自动生成。 注意: ==(等号的比较的是): 基本类型:比较的就是值是否相同。 引用类型:比较的就是地址值是否相同。 equals(该方法比较的是): 只能是引用类型:默认情况下,比较的是地址值。 不过,我们可以根据情况自己重写该方法。一般重写都是自动生成,比较的是对象的成员变量值是否相同。--------------------------------------- (4)要了解的Object类的方法 A:public int hashCode() 返回对象的哈希码值。不是实际地址值,但可以理解为地址值。 注意:哈希值是根据哈希算法计算出来的一个值,这个值和地址值有关,但是不是实际地址值。但可以理解为地址值。 B:public final Class getClass() 返回对象的字节码文件对象,反射中我们会详细讲解。 Class类的方法: public String getName() 以 String 的形式返回此 Class 对象所表示的实体名称。(实体包括:类、接口、数组名、基本类型或 void) 即:可以通过Class类中的一个方法,获取对象的真实类的全名称。 C:protected void finalize() 当垃圾回收器确定不存在对该对象的更多引用时,由对象的垃圾回收器调用此方法。用于垃圾回收,但是什么时候回收不确定。子类重写该方法,以配置系统资源或执行其他清除。 D:protected Object clone() 创建并返回此对象的一个副本。可以实现对象的克隆,包括成员变量的数据复制,但是它和两个引用指向同一个对象是有区别的。 Cloneable接口 此类实现了 Cloneable 接口,以指示 Object.clone() 方法可以合法地对该类实例进行按字段复制。 这个接口是标记接口,告诉我们只有实现该接口的类才可以实现对对象的复制了。(因为不是所有的类都可以复制的) 注意: 我们讲解的示例是一个浅度克隆,后面会学习深度克隆。 深度克隆:因为一个类可能还有父类,可能还有实现接口,那么继承体系越庞大,克隆就会变得很复杂。--------------------------------------- (5)两个注意问题: A:直接输出一个对象名称,其实是默认调用了该对象的toString()方法。 B:面试题 == 和 equals() 的区别? A:==(等号的比较的是): 基本类型:比较的是值是否相同 引用类型:比较的是地址值是否相同 B:equals(该方法比较的是): 只能比较引用类型。默认情况下,比较的是地址值是否相同。 不过,我们可以根据情况自己重写该方法。一般重写都是自动生成,比较的是对象的成员变量值是否相同。=============================================================================我的GitHub地址: https://github.com/heizemingjun 我的博客园地址: http://www.cnblogs.com/chenmingjun 我的蚂蚁笔记博客地址: http://blog.leanote.com/chenmingjun Copyright ©2018 黑泽明军 【转载文章务必保留出处和署名,谢谢!】

优秀的个人博客,低调大师

VR界的神器WakingApp让你零基础制作VR内容

WakingApp最新更新的系统版本,让任何人都可以为Oculus和Vive头显创作内容。 去年11月份完成C轮融资的WakingApp,最近发布了最新版本的VR/AR内容创作平台ENTiTi,将支持程序小白用户为Oculus Rift和HTC Vive头显创作属于自己的内容和游戏。 WakingApp是来自以色列的一家公司,他们的核心产品是一款基于云的创作平台ENTiTi,用户可通过ENTiTi平台上传文档、图片、视频、3D模型等内容,通过3D视角对上述原材料以及平台自带的工具进行查看编辑;其次通过可视化的逻辑系统建立VR/AR领域所特有的交互关系;最后所生产的内容还可通过WakingApp及合作平台进行分享与体验。简单地说,ENTiTi有点类似H5制作工具里大家熟知的易企秀、人人秀等,又有点像游戏《我的世界》,不需要任何特殊技能即可完成创建内容,并可以和朋友分享成果。 WakingApp在今年上半年就已经开放了相关平台,让所有人都可以为GearVR,Cardboard等头显创作内容。现在该应用再次更新,可以支持Oculus和Vive的内容创作。 WakingApp的董事长Alon Melchner表示:“我们的目标是为大家带来像虚拟现实、增强现实和物联网这样的未来科技,让每个人都可以参与其中,成为内容创作者,而不是当一个单纯的观众。”Alon Melchner还说,WakingApp下一次更新将会让VR和AR作为物联网的用户界面。 据了解到现在为止,并没有人通过WakingApp创作出一个完整的VR内容系统,但是WakingApp的出现,让VR和AR变得不再那么遥不可及,它会激发更多的人加入到内容创作,对于推动VR和AR产业是有很大的益处的。 原文发布时间: 2016-06-17 14:44 本文作者: 巫盼 本文来自云栖社区合作伙伴镁客网,了解相关信息可以关注镁客网。

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册
修改密码
忘记密码