Python

Methods in Strings in Python 2

AKA.DM 2024. 9. 25. 07:28
반응형

    Replace method is used to replace characters in string values.

    It takes two values in it. The first is the value we want to change, and the other is new value.

 

    For example, we wanted to get rid of the hypens between the letters of the name "joseph" below. And we did this request with the replace method.

 

    In the Replace method, we can determine the number of changes we wnat to make on the string.

 

    For example, we want to change the first 3 of the "/" characters of the object in the university variable below.

    if we specify this number as the last value in Replace, we will get the result we want.

 

    The swapcase() method converts uppercase letters in a sting value to lowercase letters and lowercase letters to uppercase characters.

 

    The capitalize() method caplitalizes only the initial letter of a sring value.

 

    The Upper method capitalizes all letters in string expression.

 

    The Lower method makes all letters in the string lowercase.

 

    The methods can be applied one after the other.

    For example, we first capitalized only the first letter with the capitalize() method. Then we converted uppercase letters to lowercase and lowercase letters to uppercase characters with the swapcase() method.

 

 

 

 

 

반응형

'Python' 카테고리의 다른 글

Indexing and Slicing in Strings in Python  (0) 2024.10.02
Methods in String in Python-3  (0) 2024.09.26
Methods in Strings in Python  (0) 2024.09.24
Boolean Logic Expression in Python  (0) 2024.09.21
Eascape Sequence Opertations in Python  (0) 2024.09.20