Uncapitalizing first letter of a name
<p>To code a name like DeAnna you type:</p>

<pre><code>name = "de\aanna" 
</code></pre>

<p>and </p>

<pre><code>print(name.title())
</code></pre>

<p>In this code <code>\a</code> capitalizes a normally uncapitalized letter. What do you code to produce a name like <code>"George von Trapp"</code> where I want to uncapitalize a normally capitalized letter?</p>

<p>The <code>\a</code> does not capitalize a letter - it is the <a href="https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals" rel="nofollow">bell escape sequence</a>.</p>

<p>The <a href="https://docs.python.org/3/library/stdtypes.html#textseq" rel="nofollow"><code>str.title</code></a> simply capitalizes the first letter of any group of letters. Since the bell is not a letter, it has the same meaning as a space. The following produces equivalent capitalization:</p>

<pre><code>name = "de anna"
print(name.title())
</code></pre>

<p>Anyways, there are no capitalize/uncapitalize magic characters in python. Simply write the name properly. If you want both a proper and a lower-case version, create the <em>later</em> via <code>str.lower</code>:</p>

<pre><code>name = "George von Trapp"
print(name, ':', name.lower())
</code></pre>

<hr>

<p>If you <strong>really</strong> want to go from <code>"georg van trapp"</code> (I'm just pretending the discussion about <code>\a</code> is over) to <code>"Georg van Trapp"</code> - welcome to having-to-decide-about-the-semantics-of-the-language-you-are-emulating.</p>

<ul>
<li><p>A simple approach is to upper-case every word, but fix some known ones.</p>

<pre><code>name = "georg van trapp"
proper_name = name.title()
proper_name.replace(' Von ', ' von ').replace(' Zu ', ' zu ').replace(' De ', ' de ')
print(name, ':', proper_name)
</code></pre></li>
<li><p>You can do that with a <code>list</code>-and-loop approach for less headache as well:</p>

<pre><code>lc_words = ['von', 'van', 'zu', 'von und zu', 'de', "d'", 'av', 'af', 'der', 'Teer', "'t", "'n", "'s"]
name = "georg van trapp"
proper_name = name.title()
for word in lc_words:
    proper_name = proper_name.replace(' %s ' % word.title(), ' %s ' % word)
print(name, ':', proper_name)
</code></pre></li>
<li><p>If names are of the form <code>First Second byword Last</code>, you can capitalize everything but the second-to-last word:</p>

<pre><code>name = "georg fritz ferdinand hannibal van trapp"
proper_name = name.title().split()  # gets you the *individual* words, capitalized
proper_name = ' '.join(proper_name[:-2] + [proper_name[-2].lower(), proper_name[-1]])
print(name, ':', proper_name)
</code></pre></li>
<li><p>Any words that are shorter than four letters (warning, not feasible for some names!!!)</p>

<pre><code>name = "georg fritz theodores ferdinand markus hannibal von und zu trapp"
proper_name = ' '.join(word.title() if len(word) &gt; 3 else word.lower() for word in name.split())
print(name, ':', proper_name)
</code></pre></li>
</ul>

python string python-3.x