摘要: /* 有关isdigit()函数,参数只能是字符类型 */ #include<iostream> #include<cctype> using namespace std; int main() { /* 无论输入什么数字,结果都是非数字 int a; cout << "输入一个数字,非数字自动退出 阅读全文
posted @ 2020-09-07 10:39 河马哥 阅读(328) 评论(0) 推荐(0) 编辑
摘要: /* 输入3个数,从小大排列 */ #include<stdio.h> #include<stdlib.h> int main(void) { void daxiao(int *p,int n); printf("请输入3个数字:"); int a[3]; for(int i = 0; i < 3; 阅读全文
posted @ 2020-07-07 20:00 河马哥 阅读(207) 评论(0) 推荐(0) 编辑
摘要: //可能有误解,后面再改 #include<stdlib.h> #include<stdio.h> int main(void) { int he(int *p,int n); //函数声明 int he_1(int (*p)[3],int n); int a[5] = {1,2,3,4,5}; i 阅读全文
posted @ 2020-07-07 11:55 河马哥 阅读(114) 评论(0) 推荐(0) 编辑
摘要: /* 2020,6,20,动态构建一维数组 str = (char *) realloc(str, 25);动态调整分配的内存大小 */ #include<stdio.h> #include<malloc.h> int main(void) { int a; int * li; printf("请输 阅读全文
posted @ 2020-07-06 20:29 河马哥 阅读(864) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h> int main(void) { int li[2][3] = { {1,2,3}, {11,22,33} }; int *p; //第一种 p = &li[0][0]; for(int i = 0; i < 6; i++) { //printf("%d\n",p 阅读全文
posted @ 2020-07-06 20:00 河马哥 阅读(243) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h> int main(void) { //指向常量的指针:const 类型 * 指针名 int i = 10; const int *p = &i; //*p = 0; //报错 printf("%d\n",*p); //总结,前置const不能通过指针改变指向的地址 阅读全文
posted @ 2020-07-06 17:04 河马哥 阅读(248) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h> int main(void) { //指针的运算 int * p; p = NULL; //表示是个空指针 p++; //p = p + 1,p的值是0加上sizeof(int)*1 printf("加运算:%d\n",p); //结果是4,因为int类型占用4个 阅读全文
posted @ 2020-07-06 16:44 河马哥 阅读(373) 评论(0) 推荐(0) 编辑
摘要: /* putchar函数,用于输出一个字符 getchar函数,用于输入一个字符A */ #include<stdio.h> int main(void) { char a, b, c; a = getchar(); //获取输入的一个字符 b = getchar(); //如果输入过程中输入回车, 阅读全文
posted @ 2020-07-05 08:44 河马哥 阅读(142) 评论(0) 推荐(0) 编辑
摘要: /* 指向函数的指针变量 类型名(*指针变量名)(函数参数列表) 类型名是函数的返回值类型 指向函数的指针变量只能指向定义时指定类型的函数 指向函数的指针变量不可以进行加减等运算 用函数名调用函数只能调用指定的一个,指针变量调用可以视情况先后调用不同的同类型函数 */ #include<stdio. 阅读全文
posted @ 2020-06-24 10:04 河马哥 阅读(539) 评论(0) 推荐(0) 编辑
摘要: /* 数组名和字符指针变量区别在P262 */ #include<stdio.h> //void copy(char a[],char b[]) //定义一个复制字符串的函数 void copy(char *a, char *b) //等价于传入数组名 { int i; // for(i =0; a 阅读全文
posted @ 2020-06-23 16:27 河马哥 阅读(619) 评论(0) 推荐(0) 编辑
摘要: 字典内置函数&方法 Python字典包含了以下内置函数: 1 cmp(dict1, dict2) 比较两个字典元素。 2 len(dict) 计算字典元素个数,即键的总数。 3 str(dict) 输出字典可打印的字符串表示。 4 type(variable) 返回输入的变量类型,如果变量是字典就返 阅读全文
posted @ 2020-04-15 15:31 河马哥 阅读(515) 评论(0) 推荐(0) 编辑
摘要: Python列表函数&方法 增: list.append(obj) 在列表末尾添加新的对象 拼接: list.extend(seq) 在列表末尾一次性追加另一个序列中的多个值(用新列表扩展原来的列表 插入: list.insert(index, obj) 将对象插入列表 删: list.pop([i 阅读全文
posted @ 2020-04-15 14:04 河马哥 阅读(343) 评论(0) 推荐(0) 编辑
摘要: 大小写: capitalize() 把字符串的第一个字符大写 title() 返回"标题化"的 string,就是说所有单词都是以大写开始,其余字母均为小写 upper() 转换 string 中的小写字母为大写 lower() 转换 string 中所有大写字符为小写. swapcase() 转换 阅读全文
posted @ 2020-04-15 13:42 河马哥 阅读(186) 评论(0) 推荐(0) 编辑
摘要: #文件名 # apple 12 2 # fhal 34 1 # fsdh 45 5 # fjff 2000 6 # ddd 10 3 # with open('aaa.txt',encoding='utf-8',mode='r') as f1: # lis = [] # for line in f1 阅读全文
posted @ 2020-03-28 20:41 河马哥 阅读(355) 评论(0) 推荐(0) 编辑
摘要: 问题: 过滤用户输入中前后多余的空白字符 ‘ ++++abc123 ‘ 过滤某windows下编辑文本中的'\r': ‘hello world \r\n' 去掉文本中unicode组合字符,音调 "Zhào Qián Sūn Lǐ Zhōu Wú Zhèng Wáng" 如何解决以上问题? 去掉两端 阅读全文
posted @ 2020-03-28 19:15 河马哥 阅读(4456) 评论(0) 推荐(0) 编辑
摘要: cars = ['鲁A32444','鲁B12333','京B8989M','黑C49678','黑C46555','沪 B25041'] locals = {'沪':'上海','黑':'黑龙江','鲁':'山东','鄂':'湖北','湘':'湖南','京':'北京&# 阅读全文
posted @ 2020-03-28 16:51 河马哥 阅读(547) 评论(0) 推荐(0) 编辑
摘要: #把列表中所有周姓的人的信息删掉 lst = ['周老二','周星星','麻花藤','周扒皮','大周'] li = [] for i in lst: if i.strip()[0] != '周': li.append(i) lst = li print(lst) #倒序 lst = ['周老二', 阅读全文
posted @ 2020-03-28 13:25 河马哥 阅读(188) 评论(0) 推荐(0) 编辑
摘要: while 1: num = input('请输入一个三位数:') count = 0 if num.isdecimal() and 100 <= int(num) < 1000: for i in num: count = count + int(i) ** 3 if count == int(n 阅读全文
posted @ 2020-03-28 13:18 河马哥 阅读(342) 评论(0) 推荐(0) 编辑
摘要: dic = {'a1':'he','a2':'ma','a3':'ye','height':20,'sex':'male'} #把KEY转换成列表,再遍历列表 for key in list(dic.keys()): if 'a' in key: dic.pop(key) print(dic) #创 阅读全文
posted @ 2020-03-27 13:05 河马哥 阅读(262) 评论(0) 推荐(0) 编辑
摘要: #倒序删除 li1=[00,11,22,33,44,55,66,77,88,99] count = len(li1)-1 while count >= 0: if count % 2 != 0: li1.pop(count) count -= 1 print(li1) #切片法 li1=[00,11 阅读全文
posted @ 2020-03-27 12:51 河马哥 阅读(599) 评论(0) 推荐(0) 编辑