Java判断一个字符串中有多少大写字母.小写字母和数字 思路: 大写字母就是A-Z之间,小写字母是a-z之间,数字就是0-9之间,于是做判断就好:用到的String知识点,遍历字符串, 长度方法length() 和转char数据类型的toCharArray()方法. 代码如下: import java.util.Scanner; public class Test { public static void main(String[] args) { System.out.println("請輸入
def a4(arg): ret = {} for key,value in arg.items(): if len(value) > 2: ret[key] = value[0:2] else: ret[key] = value return ret dic = {"} r = a4(dic) print(r)
def a3(arg): ret = [ ] for i in range(len(arg)): if i % 2 == 1: ret.append(arg[i]) else: pass return ret li = [11,22,33,44,55] r = a3(li) print(li) print(r)
1.for实现: str1 = str.strip(input("please input a str:"))n = 1i = 0for i in range(len(str1)-1): if str.isalnum(str1[i]) != str.isalnum(str1[i+1]): n += 1 else: i += 1print("字符个数为:",int((n+1)/2)) 2.while实现: # str1 = str.strip(input("
DELIMITER $$ DROP FUNCTION IF EXISTS `Fun_GetPY`$$ CREATE FUNCTION `HIS`.`Fun_GetPY` (in_string VARCHAR(21845)) RETURNS VARCHAR(21845) CHARSET utf8 BEGIN #截取字符串,每次做截取后的字符串存放在该变量中,初始为函数参数in_string值 DECLARE tmp_str VARCHAR(21845) CHARSET gbk DEFAULT ''
dic=dict() d={} s=set() s='helloworld' (1)d=dict() for x in s: if x not in d.keys(): d[x]=1 else: d[x]=d[x]+1 print(d) (2)d2=dict() for x in s: d2[x]=d2.get(x,0)+1 print(d2) (3)d3=dict() for x in s: d3[x]=s.count(x) print(d3) 上面一共给出了三种方法,均是以字典的形式输出,但
用Python写了一个postgresql函数,感觉很爽 CREATE LANGUAGE plpythonu; postgresql函数 CREATE OR REPLACE FUNCTION myfun1(text) RETURNS text AS $BODY$ s = args[0] h = 0; n = len(s); for i, c in enumerate(s): h = h + ord(c)*31**(n-1-i); bits = 4*8; return (h +