0% found this document useful (0 votes)
20 views7 pages

Python

The document describes various string methods in Python and their uses. Some key string methods include capitalize() to capitalize the first character, casefold() to convert to lowercase, center() to center align text, count() to count occurrences of a substring, and format() to format strings with values.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
20 views7 pages

Python

The document describes various string methods in Python and their uses. Some key string methods include capitalize() to capitalize the first character, casefold() to convert to lowercase, center() to center align text, count() to count occurrences of a substring, and format() to format strings with values.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 7

Method Description

capitalize() Converts the first character to upper case

casefold() Converts string into lower case

center() Returns a centered string

count() Returns the number of times a specified value occurs in a string

encode() Returns an encoded version of the string

endswith() Returns true if the string ends with the specified value

expandtabs() Sets the tab size of the string

find() Searches the string for a specified value and returns the position of wher
found

format() Formats specified values in a string

format_map( Formats specified values in a string


)
index() Searches the string for a specified value and returns the position of wher
found

isalnum() Returns True if all characters in the string are alphanumeric

isalpha() Returns True if all characters in the string are in the alphabet

isascii() Returns True if all characters in the string are ascii characters

isdecimal() Returns True if all characters in the string are decimals

isdigit() Returns True if all characters in the string are digits

isidentifier() Returns True if the string is an identifier

islower() Returns True if all characters in the string are lower case

isnumeric() Returns True if all characters in the string are numeric

isprintable() Returns True if all characters in the string are printable

isspace() Returns True if all characters in the string are whitespaces

istitle() Returns True if the string follows the rules of a title


isupper() Returns True if all characters in the string are upper case

join() Converts the elements of an iterable into a string

ljust() Returns a left justified version of the string

lower() Converts a string into lower case

lstrip() Returns a left trim version of the string

maketrans() Returns a translation table to be used in translations

partition() Returns a tuple where the string is parted into three parts

replace() Returns a string where a specified value is replaced with a specified valu

rfind() Searches the string for a specified value and returns the last position of
was found

rindex() Searches the string for a specified value and returns the last position of
was found

rjust() Returns a right justified version of the string

rpartition() Returns a tuple where the string is parted into three parts
rsplit() Splits the string at the specified separator, and returns a list

rstrip() Returns a right trim version of the string

split() Splits the string at the specified separator, and returns a list

splitlines() Splits the string at line breaks and returns a list

startswith() Returns true if the string starts with the specified value

strip() Returns a trimmed version of the string

swapcase() Swaps cases, lower case becomes upper case and vice versa

title() Converts the first character of each word to upper case

translate() Returns a translated string

upper() Converts a string into upper case

zfill() Fills the string with a specified number of 0 values at the beginning

‫ال يغيرون السلسلة األصلية‬ .‫جميع طرق السلسلة ترجع قي ًما جديدة‬ :‫مالحظة‬.


x = ("apple", "banana", "cherry")
print(type(x))

tuple

x = {"name" : "John", "age" : 36}


print(type(x))

DICT

x = True
print(type(x))

BOOL

1. Insert the correct syntax to convert x into a floating point number.

x = 5
float
x = (x)

2. Insert the correct syntax to convert x into a integer.

x = 5.5
int
x = (x

Insert the correct syntax to convert x into a complex number.

x = 5
complex
x = (x)
Use the len method to print the length of the string.

x = "Hello World"
len(x)
print( )

Get the first character of the string txt.

txt = "Hello World"


txt[0]
x =
Get the characters from index 2 to index 4 (llo).

txt = "Hello World"


x = txt[2:5]

Return the string without any whitespace at the beginning or the end.

txt = " Hello World "


txt.strip()
x =

You might also like