- 博客(7)
- 收藏
- 关注
原创 for循环运行逻辑
除了while循环,C语言中还有for循环,它的使用更加灵活,完全可以取代while 循环。 上节我们使用 while 循环来计算1加到100的值,代码如下: #include <stdio.h> int main(){ int i, sum=0; i = 1; //语句① while(i<=100 /*语句②*/ ){ sum+=i; i++; //语句③ } printf("%d\n",sum); return 0; } 可以看到,语句①②③被放到了...
2022-04-18 21:47:04
1538
转载 C语言中 数组名 和 &数组名
== 实验环境 == 1. 编译器:gcc 5.4.0 2. 操作系统:Ubuntu 16.04 x86_64 缘起 本以为此知识点我已熟练掌握,可是最近应用的时候还真给记混淆了。所以写篇文章加深印象。 Show me the code 废话少说,show me the code. #include <stdio.h> int main(void) { int array[5] = {0}; printf("1. array = %p\n", arr...
2022-03-21 10:54:34
476
原创 python求绝对值得方法
abs()是一个内置函数,而fabs()在math模块中定义的。 fabs()函数只适用于float和integer类型,而abs()也适用于复数。 abs()返回是float和int类型,math.fabs()返回是float类型
2022-03-18 09:35:14
697
原创 python eval函数使用方法
eval是Python的一个内置函数,功能十分强大,这个函数的作用是,返回传入字符串的表达式的结果。就是说:将字符串当成有效的表达式 来求值 并 返回计算结果。 eval函数就是实现list、dict、tuple与str之间的转化,同样str函数把list,dict,tuple转为为字符串 1.eval的语法 eval(expression[, globals[, locals]]) expression : 表达式。 globals : (可选参数)变量作用域,全局命名空间,如果被提供,...
2022-02-10 13:10:35
1052
原创 【python】strip及rstrip使用方法
print( 'mississippi'.rstrip('ip')) #输出的结果是mississ print( 'workplace'.strip('wce')) #输出的结果是orkpla strip函数会去掉首尾指定字符直到下一个字符不是指定的字符为止。
2022-01-19 15:53:55
446
原创 python replace和re.sub的两种替换方法
# 1、用字符串本身的replace方法 # 复制代码代码如下: a='hello,world,world' print(a.replace('world','python',1)) #1:最高代替次数 #输出的结果是hello,python,world # 2、用正则表达式来完成替换: # 复制代码代码如下: import re # strinfo=re.compile('world') # b=strinfo.sub('python',a) strinfo=re.compile('world') b=.
2022-01-19 15:37:08
874
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人