或Python 3变量中的语句

时间:2018-01-09 16:52:04

标签: python

我正在尝试创建一个简单的python程序,在一个单词的开头检测一个constanant并将其移动到最后(如piglatin)。我可以制作像

这样的变量吗?
conts = "b" or "c"

然后if / else检测单词是以b还是c开头。这可能吗?

1 个答案:

答案 0 :(得分:0)

你无法做到这一点,但一个简单的选择是使用conts = {'a', 'b'} my_string = 'apples' if my_string[0] in conts: print(my_string[1:] + my_string[0]) else: print(my_string) 运算符。

    var token = "";
    var id = "";
    var cms = {
        login: function() {
            return request({
                "method":"POST", 
                "uri": process.env.CMS_URL + "/cms/login",
                "json": true,
                "body": {
                    "email":"xxxxxxx",
                    "password":"xxxxx"
                }
            }).then(response => {
                console.log("Successfully logged in to cms. Access token: " + response);
                token = response;
            }).catch(error => {
                console.log("Couldn't get access token from cms");
            });   
        },
        createCollection: function(token){
            return request({
                "method":"POST", 
                "uri": process.env.CMS_URL + "/cms/collection",
                "json": true,
                "headers" : {
                    "X-Cms-Token":token
                },
                "body": {
                    "name":"Acceptance test collection",
                    "type":"manual"
                }
            }).then(response => {
                console.log("Successfully created a collection.");
                id = response.id;
            }).catch(error => {
                console.log("Collection already exists");
            }); 
        },
        deleteCollection: function(token, id){
            return request({
                "method":"DELETE", 
                "uri": process.env.CMS_URL + "/cms/collection" + id,
                "json": true,
                "headers" : {
                    "X-Cms-Token":token
                }
            }).then(response => {
                console.log("Successfully deleted collection.");
            }).catch(error => {
                console.log("No collection to delete");
                console.log(error);
            }); 
        }     
    };  
    var createCollectionCms = function(token, id){
        return new Promise((resolve) => {
            cms.login()
                .then(zebedee.createCollection(token))
                .then(zebedee.deleteCollection(token,id));
            setTimeout(resolve, 6000);
        });
    }
    createCollectionCms();