String Functions
Python string functions:
Python has a set of built-in methods that you can use on strings.
All string methods returns new values. They do not change the original string.
1.**capitalize(): **Capitalizes the first character of the string.
name = "pritha" print(name.capitalize())
Pritha
2.casefold():Converts string into lower case
name = "PRITHA" print(name.casefold())
pritha
3.center():Returns a centered string
name = "pritha" print(name.center(10,"-"))
--pritha--
4.count():Returns the number of times a specified value occurs in a string
name = "lakshmipritha" print(name.count('a'))
2
5.encode():Returns an encoded version of the string
name = "lakshmipritha" print(name.encode())
b'lakshmipritha'
6.endswith():Returns true if the string ends with the specified value
name = "lakshmi pritha" print(name.endswith('pritha'))
True
7.find():Searches the string for a specified value and returns the position of where it was found
name = "lakshmi pritha" print(name.find('pritha'))
8
8.format():Formats specified values in a string
name = "Hello, {}. Welcome to {}." print(name.format("Pritha", "Python"))
Hello, Pritha. Welcome to Python.
9.format_map():Formats specified values in a string
text = "My name is {name} and I am {age} years old." data = {"name": "Pritha", "age":30 } print(text.format_map(data))
My name is Pritha and I am 30 years old.
10.index():Searches the string for a specified value and returns the position of where it was found
name= "lakshmi pritha" position = name.index("pritha") print(position)
8
11.isalnum():Returns True if all characters in the string are alphanumeric
12.isalpha():Returns True if all characters in the string are in the alphabet
13.isascii():Returns True if all characters in the string are ascii characters
14.isdecimal():Returns True if all characters in the string are decimals
15.isdigit():Returns True if all characters in the string are digits
16.isidentifier():Returns True if the string is an identifier
17.islower():Returns True if all characters in the string are lower case
18.isnumeric():Returns True if all characters in the string are numeric
19.isprintable():Returns True if all characters in the string are printable
20.isspace():Returns True if all characters in the string are whitespaces
21.istitle():Returns True if the string follows the rules of a title
22.isupper():Returns True if all characters in the string are upper case
name = "pritha" print(name.isalnum()) print(name.isalpha()) print(name.isascii()) print(name.isdecimal()) print(name.isdigit()) print(name.isidentifier()) print(name.islower()) print(name.isnumeric()) print(name.isprintable()) print(name.isspace()) print(name.istitle()) print(name.isupper())
True True True False False True True False True False False False
The above is the detailed content of String Functions. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

Fastapi ...

Using python in Linux terminal...

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

Understanding the anti-crawling strategy of Investing.com Many people often try to crawl news data from Investing.com (https://cn.investing.com/news/latest-news)...
