分号是做什么用的? [英] What does a semicolon do?

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

问题描述

我在线获得了一个功能来帮助我完成当前的项目,并且其中的某些行带有分号。我想知道为什么?

I got a function online to help me with my current project and it had semicolons 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;

我上线的功能几乎没有修改:

The function I got online with little modification:

for string in strings:
    for char in string:
        if char in alphabet: return 1;

上面是说以下内容吗?

if char in alphabet:
    return 1
    break


推荐答案

分号在您显示的代码中没有任何作用。

The semicolon does nothing in the code you show.

我怀疑这是用另一种语言编程的人(C,Java,...)在语句末尾需要分号,这只是一种习惯(有时也对我来说是一种习惯)。

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).

如果您想放同一行上有多个Python语句,您可以使用分号将它们分开,请参见 Python文档

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

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

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