Sublime Text 3中的“ print”语法无效

时间:2019-10-18 14:26:18

标签: python python-3.x printing sublimetext3

使用Sublime Text时,显示无效语法。但是像hackerearth交互式编辑器这样的在线编辑器不会显示任何错误,并且python shell命令也可以。

崇高文字3.2.2

python 3.6

print(result [i],end =“”)

SyntaxError:语法无效

在在线编辑器中

submit(ev) {
    ev.preventDefault();

    setTimeout(() => {
        this.setState({loading: true});
    }, 0);

    const {email, password} = ev.target.elements;

  app.auth().setPersistence(firebase.auth.Auth.Persistence.NONE);
    // As httpOnly cookies are to be used, do not persist any state client side.
    app.auth().signInWithEmailAndPassword(email, password).then(user => {
        // Get the user's ID token as it is needed to exchange for a session cookie.
        app.auth().onAuthStateChanged((user) => {
            if (user) {
                this.setState({loading: true});
                return user.getIdToken().then(idToken => {
                    // Session login endpoint is queried and the session cookie is set.
                    // CSRF protection should be taken into account.
                    const csrfToken = Utils.getCookie('csrfToken');
                    return this.postIdTokenToSessionLogin('/auth/session-login', idToken, csrfToken, "auth");
                });
            } else {
                this.setState({error: "There was an error", loading: false});
            }
        });
    }).catch(error => {
        this.setState({error: error.message, loading: false});
    })
}

在Sublime文本中:

def selection_sort(arr, n, x):        
    for i in range(x):
        min_idx = i
        for j in range(i+1, len(arr)):
            if arr[min_idx] > arr[j]:
                min_idx = j

        arr[i], arr[min_idx] = arr[min_idx], arr[i]
    return arr

if __name__ == "__main__":
    n, x = map(int, input().split())
    arr = list(map(int, input().strip().split()))[:n]
    result = selection_sort(arr, n, x)
    for i in range(len(result)):
        print(result[i], end=" ")

4 个答案:

答案 0 :(得分:1)

如果您同时拥有python 2和python 3,则可能会导致问题。 试试

import sys
sys.version

检查它是否为版本3

答案 1 :(得分:1)

https://www.geeksforgeeks.org/gfact-50-python-end-parameter-in-print/

# This Python program must be run with 
# Python 3 as it won't work with 2.7. 

# ends the output with '@' 
print("Python" , end = '@')  
print("GeeksforGeeks") 
  

仅适用于python 3

我确实尝试过使用崇高的文本来编写程序。.适用于python 3,而不适用于python2。因此,您绝对应该检查version of python your calling the function with

答案 2 :(得分:1)

请检查版本,并且版本2和3的语法略有更改。在编码时必须考虑。 快乐编码

答案 3 :(得分:1)

在这种情况下,您可以使用from __future__ import print_function隔离Python 2 vs 3问题。有关详细信息,请参见https://docs.python.org/2/library/future.html