Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you capitalize the first two letters

Tags:

python

string

I have usernames that are in this format RSmith. I can put them in all upercase or Title them to look like this, Rsmith, but I need RSmith.

current script:

import csv

app_csv = ('/tmp/lowerAccounts.csv')
app_csv_upper = ('/tmp/Identity_Accounts.csv')
in_app_csv = open(app_csv)
out_app_csv = open(app_csv_upper, 'w')
inreader = csv.reader(in_app_csv)
outwriter = csv.writer(out_app_csv)
for row in inreader:
    outwriter.writerow(row)
    row[0] = row[0].upper()
    outwriter.writerow(row)
    row[0] = row[0].title(row)
    outwriter.writerow(row)
like image 846
Jack McClure Avatar asked Apr 03 '18 20:04

Jack McClure


People also ask

What are 2 rules you remember about capitalizing?

In general, you should capitalize the first word, all nouns, all verbs (even short ones, like is), all adjectives, and all proper nouns. That means you should lowercase articles, conjunctions, and prepositions—however, some style guides say to capitalize conjunctions and prepositions that are longer than five letters.

How do you capitalize first letter?

To use a keyboard shortcut to change between lowercase, UPPERCASE, and Capitalize Each Word, select the text and press SHIFT + F3 until the case you want is applied.

Can a name have 2 capital letters?

Since they were used to prefix names which are proper nouns in themselves, the derived surnames have two capital letters. e.g. FitzGerald, McDonald, MacIntyre, O Henry etc. However, this isn't a rule.


1 Answers

You can use basic string slicing:

s = 'rsmith'
s = s[:2].upper() + s[2:]
print(s)

Output:

RSmith
like image 108
user3483203 Avatar answered Nov 14 '22 23:11

user3483203