分号有什么作用? [英] What does a semicolon do?

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

问题描述

我在网上找到了一个函数来帮助我完成当前的项目,它在某些行上有分号.我想知道为什么?是不是破坏功能?

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;

我上网修改的功能:

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

以上是不是下面的内容?

Is the above saying the following?

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天全站免登陆