Python:什么是半冒号做的? [英] Python: What Does a Semi Colon Do?

查看:157
本文介绍了Python:什么是半冒号做的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在线获得了一个函数来帮助我处理当前的项目,并且在某些行上有分号。我想知道为什么?是否打破了功能?

  def containsAny(self,strings = []):
alphabet ='abcdefghijklmnopqrstuvwxyz0123456789 '
在字符串中的字符串:
在字符串中的字符串:
如果字符串中的字符:return 1;
返回0;

函数我在线修改很少:

 在字符串中的字符串:
在字符串中的字符串:
如果字符串中的字符:return 1;

这是^表示

  if字母表中的字符:
返回1
break

感谢您的帮助。

解决方案

分号在您显示的代码中不会做任何事。
$ b

我怀疑这是用另一种语言(C,Java,...)编程的人,在语句结尾需要分号,这只是一种习惯(有时也会发生)。 / p>

如果您想在同一行放置多个Python语句,您可以使用分号分隔它们,请参阅 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:

A suite is a group of statements controlled by a clause. A suite can be one or more semicolon-separated simple statements on the same line as the header, following the header’s colon, or it can be one or more indented statements on subsequent lines

这篇关于Python:什么是半冒号做的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆