练习课题链接:廖雪峰-Python教程-高级特性-迭代 学习记录: 1.Python当中类似于 三目运算符 的应用 2.Python用input函数输入一个列表 代码实例:对用户输入的一组数字转化成list,再对list内的数进行比较,判断出最大值和最小值并打印输出. def findMinAndMax(L): #首先用 if 来判断list是否为空,若为空,则直接返回None if len(L) == 0: return(None, None) else: min = L[0] max = L
今天在QQ群上看见有人问如何在Java中输入一个字符的问题. 查了下有以下三种方法吧: char c = new java.util.Scanner(System.in).next().charAt(0); 这算是最常用的了吧,实际上就是输入字符串后再利用charAt(0)得到 char c = new java.util.Scanner(System.in).next().toCharArray()[0]; 勉强算得上第二种吧!我以前很常用的.可以用,但是毕竟不好,浪费资源,又没有第一种简单.
python3.5 for循环每次取出一个字符(不是字节) #!/usr/bin/env python # -*- coding:utf-8 -*- my_str = "我是哈哈" for i in my_str: my_bytes = bytes(i, 'utf-8') print(my_bytes) my_bytes = bytes(i, 'gbk') print(my_bytes) for i in my_str: my_bytes = bytes(i, 'utf-8') for
python每次处理一个字符的三种方法 a_string = "abccdea" print 'the first' for c in a_string: print ord(c)+1 print "the second" result = [ord(c)+1 for c in a_string] print result print "the thrid" def do_something(c): return ord(c)+1 result
""" Python3.4[文本]之每次处理一个字符 """ test_str = "my name is bixiaopeng" for x in range( 0, len(test_str)-1): print ("## 通过索引遍历字符串: " + test_str[x]) for x in test_str: print ("## 直接遍历字符串: " + x) thelist
You enter a URL into the browser输入一个url地址 The browser looks up the IP address for the domain name浏览器查找域名的ip地址(浏览器缓存→系统缓存→路由器缓存→ISP DNS缓存→从根域名服务器递归搜索) The browser sends a HTTP request to the web server浏览器给web服务器发送一个HTTP请求 The facebook server responds
在Python中字符就是长度为1的字符串,所以可以循环遍历一个字符串,依次访问每一个字符,得到你想要的处理前提: 一个列表是个好主意,就像这样:thelist = list(thestring) 当然,完全可以不用列表,对于喜欢循环遍历的人,他们有足够的理由这么做,因为并没有创建列表的过程: for c in thestring: do_something_with(c) 知道列表推导的人,肯定不屑于上面的写法,因为下面的代码是他们常引以为豪的: results = [do_something_