Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使python仅使用大写变量_Python - Fatal编程技术网

如何使python仅使用大写变量

如何使python仅使用大写变量,python,Python,我在论坛上寻找一些工作人员,但一切看起来都很复杂,或者只让第一个字母变大,其他字母变小等等。 有没有办法把第一个字母改成大写?比如: test = 'someThing' anotherTest = test(it will become 'SomeThing') “someThing”。标题会将单词的其余部分降格,因此您只需针对第一个字母: >>> var = 'someThing' >>> print(var.title()) Something >

我在论坛上寻找一些工作人员,但一切看起来都很复杂,或者只让第一个字母变大,其他字母变小等等。 有没有办法把第一个字母改成大写?比如:

test = 'someThing'
anotherTest = test(it will become 'SomeThing')
“someThing”。标题会将单词的其余部分降格,因此您只需针对第一个字母:

>>> var = 'someThing'
>>> print(var.title())
Something
>>> print(var[0].title() + var[1:])
SomeThing
看起来很复杂,我知道,但是没有默认的字符串操作符。您始终可以将其包装在一个简单的函数中:

def CamelCase(s):
    return s[:1].title() + s[1:]

通过使用范围s[:1],我避免了空字符串上的错误。

。上限可能更清晰。克里斯,我认为这取决于个人偏好。对我来说,在一封信上用标题来说明整个结构的意图,所以我认为这是清楚的。同意它是主观的,但对我来说,如果你想表现出意图,上图更为广为人知。titleI特别选择了标题而不是大写,因为在我的经验中,这是我经常看到的。我的情况如下:-