#判断

判断一个数是否是4的n次方

 defis_Power_of_four(n):whilenandnot(n&0b11):n>>=2return(n==1)print(is_Power_of_four(4))print(is_Power_of_four(12))print(is_Power_of_four(16))pri...

c++ 判断list是否为空(empty)

 #include<list>#include<iostream>usingnamespacestd;intmain(){list<int>numbers;cout<<"Initially,numbers.empty():"<<numbers.emp...

c++ 判断容器是否为空

 #include<iostream>#include<vector>#include<string>usingnamespacestd;intmain(){vector<int>ints{1,2,4};vector<string>fruits{"o...
代码星球 ·2020-08-09

shell 判断字符串长度是否不为0

 test.sh#!/bin/bashs1=""iftest$s1;thenecho"lengthisnotzero"elseecho"thelengthis0"fis2="shell"iftest$s2;thenecho"lengthisnot0"elseecho"thelengthis0"fi执行sudo...

shell 判断字符串长度是否为0

 test.sh#!/bin/bashecho"enterthestring:"readfilenameiftest-z$filename;thenecho"thelengthis0"elseecho"thelengthisnot0"fi执行sudochmod+xtest.sh./test.sh输出enter...

shell 判断一个字符串是否为空

 test.sh#!/bin/bashecho"enterthestring:"readfilenameiftest$filename;thenecho"it'snotzero"elseecho"it'szero"fi执行sudochmod+xtest.sh./test.sh输出enterthestring:...

shell 判断是否是目录

  创建一个文件和一个文件夹touchsssmkdirdtest.sh#!/bin/bashecho"enterthename:"readfilenameiftest-d$filename;thencd$filenamepwdelseecho"it'snotadirectory!"fi 执...
代码星球 ·2020-08-09

shell 判断文件是否是可执行文件

 测试变量指定的文件是否存在且是可执行文件。如果存在且是可执行文件,则执行该文件,否则通过chmod命令赋予该文件可执行权限。//test.sh#!/bin/bashecho"enterthename:"readfilenameiftest-x$filename;then./$filenameelsesudo...

shell 判断文件是否存在,没有则创建

 没有该文件则创建,有则ls-l输出文件信息。#!/bin/bashecho"enterthename:"readfilenameiftest-e$filename;thenls-l$filenameelsetouch$filenamefi输出enterthename:sss.sh-rwxr-xr-x1roo...

python 判断是否是元音字母

 defis_vowel(char):all_vowels='aeiou'returncharinall_vowelsprint(is_vowel('c'))print(is_vowel('e')) ...

python判断key是否存在

 d={1:10,2:20,3:30,4:40,5:50,6:60}defis_key_present(x):ifxind:print('Keyispresentinthedictionary')else:print('Keyisnotpresentinthedictionary')is_key_presen...

python 判断字典是否为空

 my_dict={}ifnotbool(my_dict):print("Dictionaryisempty") ...
代码星球 ·2020-08-09

shell 判断变量是否为空

 一句话判断[!$a]&&echo"aisnull" 1.判断变量read-p"inputaword:"wordif[!-n"$word"];thenecho"youhavenotinputaword!"elseecho"thewordyouinputis$word"fi或者#!/b...
代码星球 ·2020-08-09

python 判断列表字符串元素首尾字符是否相同

 defmatch_words(words):ctr=0forwordinwords:iflen(word)>1andword[0]==word[-1]:ctr+=1returnctrprint(match_words(['abc','xyz','aba','122771'])) ...

python 判断两个列表是否有公共元素

 defcommon_data(list1,list2):result=Falseforxinlist1:foryinlist2:ifx==y:result=Truereturnresultprint(common_data([1,2,3,4,5],[5,6,7,8,9]))print(common_data...
首页上一页...2728293031...下一页尾页