> For the complete documentation index, see [llms.txt](https://yo-sarawut.gitbook.io/tutorials/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yo-sarawut.gitbook.io/tutorials/snippets/python-programming/strings-and-character-data.md).

# Strings and Character Data

### **Case Conversion**

#### [`s.title()`](https://yo-sarawut.gitbook.io/tutorials/tutorials/python/string-1/strings-and-character-data)

Converts the target string to “title case.”

```python
'the sun also rises'.title()

# 'The Sun Also Rises'
```

```python
'FOO Bar 123 baz qUX'.swapcase()  # สลับตัวเล็กตัวใหญ่

# 'foo bAR 123 BAZ Qux'

'FOO Bar 123 baz qUX'.upper() # ตัวพิมพ์ใหญ่ทั้งหมด

# 'FOO BAR 123 BAZ QUX'

'FOO Bar 123 baz qUX'.lower()  # ตัวพิมพ์เล็กทั้งหมด

# 'foo bar 123 baz qux'

s = 'foO BaR BAZ quX'  # ตัวอักษรตัวแรกเป็นตัวพิมพ์ใหญ่
s.capitalize()

#  'Foo bar baz qux'
```

### [Splitting Strings](https://yo-sarawut.gitbook.io/tutorials/tutorials/python/string-1/splitting-concatenating-and-joining-strings)

```python
str.split('a,b,c', ',')

# abc

'this is my string'.split()

#['this', 'is', 'my', 'string']

>>> s = ' this   is  my string '
>>> s.split()

#['this', 'is', 'my', 'string']

>>> s.split(' ')
#['', 'this', '', '', 'is', '', 'my', 'string', '']

# Limiting Splits With Maxsplit

>>> s = "this is my string"
>>> s.split(maxsplit=1)

#['this', 'is my string']
```

### Check Special Character

```python
# import required package 
import re 
  
# Function checks if the string 
# contains any special character 
def check_special_char(string): 
  
    # Make own character set and pass  
    # this as argument in compile method 
    regex = re.compile('[@_!#$%^&*()<>?/\|}{~:]') 
      
    # Pass the string in search  
    # method of regex object.     
    if(regex.search(string) == None): 
        print("String is accepted") 
          
    else: 
        print("String is not accepted.") 

# Enter the string 
string = "Geeks$For$Geeks"
      
# calling run function  
check_special_char(string)

 # String is not accepted. 
```

### String Constant

```python
import string

string.digits  # digit

# 0123456789

string.ascii_lowercase

# 'abcdefghijklmnopqrstuvwxyz'

string.ascii_uppercase

# 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

string.ascii_letters

# 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'

string.hexdigits

# 0123456789abcdefABCDEF

string.printable

# '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR
# STUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
```
