Science, asked by aden83332, 22 days ago

What is a correct syntax to return the first character in a string

Answers

Answered by InstaPrince
49

Required Answer:

You should use the charAt() method, at index 0, to select the first character of the string. NOTE: charAt is preferable than using [ ] (bracket notation) as str. charAt(0) returns an empty string ( '' ) for str = '' instead of undefined in case of ''[0] .

Answered by adventureisland
0

python get first character of stringpython

# Get First 3 character of a string in python

first_chars = sample_str[0:3]  

print('First 3 characters: ', first_chars)

# Output:

First 3 characters: Hel

string = 'This is a string'

print(string[0])

#output: 'T'

Similar questions