Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python get first character of string

string = 'This is a string'
print(string[0])
#output: 'T'
Comment

python get first letter of string

import re

def first_letter(s):
    m = re.search(r'[a-z]', s, re.I)
    if m is not None:
        return m.start()
    return -1

s = "##catgiraffeapluscompscI"
i = first_letter(s)
print(i)
Comment

get first letter of each word in string python

def abbrevName(name):
    xs = (name)
    name_list = xs.split()
    # print(name_list)

    first = name_list[0][0]
    second = name_list[1][0]

    return(first.upper() + "." + second.upper())
answer = abbrevName("Ozzie Smith")
print(answer) 
Comment

how to find the first letter of an item in python

mylist[0][0]   # get the first character from the first item in the list
Comment

PREVIOUS NEXT
Code Example
Python :: python dict sortieren 
Python :: python swarm plot seaborn 
Python :: load python file in jupyter notebook 
Python :: remove decimal python 
Python :: python sleep timer 
Python :: code folding vim python 
Python :: python sys.argv exception 
Python :: 2d array in python 
Python :: numpy where 
Python :: python fibonacci function 
Python :: python opérateur ternaire 
Python :: random.uniform python 
Python :: to_cvs python 
Python :: abs function in python 
Python :: python input string 
Python :: ordenar lista python 
Python :: what is kernel_initializer 
Python :: how to filter a series in pandas 
Python :: correlation between categorical and continuous variables 
Python :: sklearn random forest 
Python :: install fastapi 
Python :: is in python 
Python :: pandas ticks fontsize 
Python :: randomly pick a value in the list 
Python :: swap two columns python 
Python :: how to get mac in python 
Python :: append multiple values to 2d list python 
Python :: cosh python 
Python :: Add PostgreSQL Settings in Django 
Python :: mount gdrive in pyton 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =