问题描述
我在线获得了一个函数来帮助我处理当前的项目,并且在某些行上有分号。我想知道为什么?是否打破了功能?
def containsAny(self,strings = []):
alphabet ='abcdefghijklmnopqrstuvwxyz0123456789 '
在字符串中的字符串:
在字符串中的字符串:
如果字符串中的字符:return 1;
返回0;
函数我在线修改很少:
在字符串中的字符串:
在字符串中的字符串:
如果字符串中的字符:return 1;
这是^表示
if字母表中的字符:
返回1
break
感谢您的帮助。
分号在您显示的代码中不会做任何事。
$ b
我怀疑这是用另一种语言(C,Java,...)编程的人,在语句结尾需要分号,这只是一种习惯(有时也会发生)。 / p>
如果您想在同一行放置多个Python语句,您可以使用分号分隔它们,请参阅:
I got a function online to help me with my current project and it had semi colons on some of the lines. I was wondering why? Is it to break the function?
def containsAny(self, strings=[]):
alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789'
for string in strings:
for char in string:
if char in alphabet: return 1;
return 0;
Function I got online with little modification:
for string in strings:
for char in string:
if char in alphabet: return 1;
Is this ^ saying
if char in alphabet:
return 1
break
Thanks for any effort to help.
The semicolon does nothing in the code you show.
I suspect this is someone who programs in another language (C, Java, ...) that requires semicolons at the end of statements and it's just a habit (happens to me sometimes too).
If you want to put several Python statements on the same line, you can use a semi-colon to separate them, see this Python Doc:
这篇关于Python:什么是半冒号做的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!