PYTHON ucfirst

is this article helpful?
Python replacement for PHP's ucfirst [ edit | history ]
There is no direct equivalent. However,
result = myStr.capitalize()

is similar. It turns the first letter to uppercase and it turns all the rest of the letters to lowercase. So the above code is actually equivalent to:
$result = ucfirst(strtolower($myStr));

However, for most purposes, it should not make that much of a difference.

If you wanted an exact equivalent, you would use:
result = myStr[0].upper() + myStr[1:]

PHP ucfirst

PHP original manual for ucfirst [ show | ]


(PHP 4, PHP 5)

ucfirstMake a string's first character uppercase


string ucfirst ( string $str )

Returns a string with the first character of str capitalized, if that character is alphabetic.

Note that 'alphabetic' is determined by the current locale. For instance, in the default "C" locale characters such as umlaut-a (ä) will not be converted.



The input string.

Return Values

Returns the resulting string.


Example #1 ucfirst() example

'hello world!';
$foo ucfirst($foo);             // Hello world!

$bar 'HELLO WORLD!';
$bar ucfirst($bar);             // HELLO WORLD!
$bar ucfirst(strtolower($bar)); // Hello world!

See Also