[go: up one dir, main page]

0% found this document useful (0 votes)
4 views23 pages

functions,meathods

The document provides a comprehensive overview of various string methods and built-in functions in Python, detailing their purposes, parameters, and return values. Each method is described with specific examples of how they can be used, such as string manipulation functions like capitalize, count, and replace, as well as built-in functions like abs, all, and any. This serves as a reference for understanding how to effectively utilize these functions in Python programming.

Uploaded by

bhushan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views23 pages

functions,meathods

The document provides a comprehensive overview of various string methods and built-in functions in Python, detailing their purposes, parameters, and return values. Each method is described with specific examples of how they can be used, such as string manipulation functions like capitalize, count, and replace, as well as built-in functions like abs, all, and any. This serves as a reference for understanding how to effectively utilize these functions in Python programming.

Uploaded by

bhushan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Methods in string

string.capitalize()
Purpose: for converting first character in upper case
Parameters taking: None
Returns: capitalized version of the string (string
value)

string.casefold()
Purpose: to convert all character in lower case
Parameters taking: None
Returns: Return a version of the string

string.center (length, character)


Purpose: align string to center
Parameters taking: 1. Length int (Required), 2.
Character str (optional default is
0)
Returns: a centered string of length width

string.count (value, start, end)


Purpose: number of times a specified value appears in
the string
Parameters taking: 1. String Value (Required) for
search, 2. start int value
(optional default 0), 3. End int
value (optional Default is
the end of the string)
Returns: the number of non-overlapping occurrences
(integer value)

string.endswith (value, start, end)


Purpose: to ensure the string ends with the specified
value
Parameters taking: 1. Value Required, 2. start int
value optional 3.end int value
optional
Returns: True if S ends with the specified suffix,
False otherwise. (bool- value)

string.endswith(value, start, end)


Purpose: to verify ends with the specified suffix
Parameters taking: 1.value Required
Returns: bool value
string.expandtabs(tabsize)
Purpose: to all tab characters are expand
Parameters taking: 1.tabsize(optional)default is 8
space
Returns: None

String.find(value, start, end)


Purpose: To finds the first occurrence of the specified
value.
Parameters taking:1.value Required, 2.start int
value(optional default is 0), 3.end int value (optional
default is to end of the string)
Returns:first occurences index no will return returns -1 if
the value is not found.(int value)

string.format (value1,value2,…)
The placeholders can be identified using named
indexes {price}, numbered indexes {0}, or even empty
placeholders {}.
Purpose: formats the specified value(s) and insert them
inside the string's placeholder.
Parameters taking: 1.value, value2 Required can be any
data type
Returns: formatted string value

string.index(value, start, end)


Purpose:to find specified value index number
Parameters takin: 1. Value Required, 2. Start Optional
str (index)value default is 0, 3. End Index str
optional default is to end of the string
Returns: it returns first occurrence of specified
values index no int value if the specified value does
not found it will return value error
string.isalnum()
Purpose: to find in string values are alphanumeric (a-
z) and (0-1)
Parameters taking: not required any parameters
Returns: it returns bool value
String.isalpha()
Purpose: to find in string all values are alphabets
Parameters taking: not required any parameters
Returns: it returns bool value

string.ascii()
Purpose: to find in string all values having ascii
value
Parameters : not required any parameters

string.isdecimal()
Purpose: to find I string all valuses having decimal
value
Parameter taking: not requires any parameters
Returns: it return bool value
string.isdigit()
Purpose: to find all characters in string are in digits
Parameter taking: not required any parameters
Returns: it return bool value
string.isidentifier()
Purpose: To find string is a valid Python identifier
Parameter taking: not required any parameters
Returns: it returns bool value
String.islower()
Purpose: To find the all string is a lowercase string
Symbol,space are not checked only alphabets are checked
Parameter taking: not Required any parameters
Returns: it returns bool value

string.isnumeric()
Purpose: To find all the string is a numeric string
(+,-,*)is not concider as numeric value only(0-
9)numbers
Parameter taking: not required any parameters
Returns: it returns bool value

string.isprintable()
Purpose: to find all the string is printable
Parameter taking: not required any parameters
Returns: it returns bool value
string.isspace()
Purpose: to find the string having empty mean ‘ ‘
string
Parameters taking: not required nay parameters
Returns: it returns bool value
string.istitle()
Purpose: to find the all strings first character is in
capital letters symbols and numbers are ignored
Parameters taking: not required any parameters
String.isupper()
Purpose: to find the all strings characters in capital
letters numbers symbols add space are not checked
Parameters taking: not required nay parameters
Return: its returns bool value
string.join(iterable)
Purpose: to Concatenate any number of strings
Parameters taking: 1.Iterable object Required
Return: tis return string value
When using a dictionary as an iterable, the returned
values are the keys, not the values.

string.ljust(length, character)
Purpose: To padding is done using the specified fill
character
Parameter taking:1.lingth int value required,2.single
character str value optional default is space
Return: its return string value
str.maketrans(x, y, z)
Purpose:
Parameters takin:
Return:

str.partition(value)
Purpose: make Partition the string into three parts
using the given separator
This method searches for the first occurrence of the
specified string.
Parameters taking:1. Value str required
Return: its return tuple
str.replace(oldvalue, newvalue, count)
Purpose: all occurrences of substring old replaced by
new.
Parameters taking: 1,required oldvalue str
value ,2.required new value str, 3.count value int
optional default is all occurrence
Return: its returns string value

string.rfind(value, start, end)


Purpose: to finds the last occurrence of the specified
value.
Parameter taking: 1.value str required, 2.start int
optional Default is 0, end value int default is to the
end of the string
Return: it will return int value if specified value not
find then return -1
String.rindex(value, start, end)
Purpose: To finds the last occurrence of the specified
values index number.
Parameters takin: 1. Value str Required, 2. Starting
value int optional default is 0, end value str optional
default is to the end of the string
Return: it will return the int value if the specified
value is not found it will show ValueError
string.rjust(length, character)
Purpose: right-justified string of length width.
Parameters taking: 1, length required int, 2. Character
optional default is space
It returns string value
string.rpartition(value)
Purpose: This will search for the separator in the
string, starting at the end. If
the separator is found, returns a 3-tuple
containing the part before the
separator, the separator itself, and the part after
it.
Parameter taken: value required str
Return : tuple
string.rsplit(seprtor, maxsplit)
purpose: To splits a string into a list, starting from
the right
Parameters taken: 1. Seprator str optional space is
default, 2. Maxsplit int optional default -1 mins no
limit
Return: tuple
string.rstrip(character)
purpose: copy of the string with trailing whitespace
removed
Parameters taken: 1. Character str optional
Return: string
String.split(separator, maxsplit)
Purpose: To splits a string into a list
Parameter taken: 1.separator optional default space, 2.
Maxsplit optional default -1
Return: list
string.splitlines(keeplinebreaks)
Purpose: splits a string into a list. The splitting is
done at line breaks.
Parameters taken:1. Keeplinebreaks Optional
Returns: list

strint.startwith(value, start, end)


Purpose: To verify the string starts with the specified
value
Parameters taken: 1. Value Required str,2.start
optional int, 3. End optional int
Return: bool value
string.strip(character)
Purpose: removes any leading, and trailing whitespaces.
Leading means at the beginning of the string, trailing
means at the end.
Parameters taken: 1. Character optional
Return: string
string.swapcase()
Purpose: to make all the upper case letters are lower
case and vice versa.
Parameter taken: none
Return: string
string.title()
Purpose: a string where the first character in every
word is upper case. Like a header, or a title.
Parameter taken: none
Return: string
string.upper()
Purpose: To copy of the string converted to uppercase.
Parameters taken: none
Return : string
In-built function
abs(n)
Module: All functions are presents in built-in
functions
Purpose: To find out absolute value of the argument
Arguments:1.n required int
Return: integer
all(iterable)
purpose: To find out all items in the iterable are true
or not
If the iterable is empty (), return True.
When used on a dictionary, the all() function checks if
all the keys are true, not the values.
Arguments: 1 iterable optional
Return: booian value

any(iterable)
Purpose: to find out any object in the iterable are
true or not
If the iterable is empty(), return False
When used on a dictionary, the any() function checks if
any keys are true, not the values.
Arguments: 1.Iterable optional
Return: bool value
ascii(object)
Purpose: to find out the ascii value of the object
Arguments taking: 1. Object required
Return: ascii converted value
bin(n)
Purpose: To convert value into binary form
Argument taking: 1 n int Required
Return: binary representation of an integer.in string
value
bool(object)
Purpose: to convert object into boolian value
Argument taken: 1. Object optional
Return: bool value
bytearray(x, encoding, error)
Purpose: To convert bytearray
Argument taken:
Return: it returns bytearray value
bytes (x, encoding, error)
Purpose:
The difference between bytes() and bytearray() is
that bytes() returns an object that cannot be modified,
and bytearray() returns an object that can be modified.
Argument taken:
Return: bytes value
callable(Object)
Purpose: to check object is callable or not
Argument taken: 1.object required
Return: boolian value
chr(number)
Purpose: returns the character that represents the
specified unicode.

Argument taken:1 number required


Return: Unicode string of one character with ordinal i;
0 <= i <= 0x10ffff.
Compile
(source, filename, mode, flag, dont_inherit, optimize)
Purpose:
Argument taken: 1. source required ,2.filename required
3. Mode required, 4 flag optional default 0,
5.dont_inherit optional default False , 6.optimize
optional default -1
Return: code value
complex(real, imaginary)
Purpose: to Create a complex number from a real part
and an optional imaginary part
Argument taken: 1.real required int, 2, imaginary
optional int default 0
Return: complex value
delattr(object, attribute)
Purpose: To delete the specified attribute from the
specified object.
Argument taken: 1. Object required, 2. Attribute
required
Return: NoneType
dict(keywordargumtnts)
Purpose: to create dictionary object
Arguments taken: keyword arguments optional
Return: dict value
dir(object)
purpose: returns all properties and methods of the
specified object, without the values.
Argument taken: 1.object
Return: List
divmod(dividend, divisor)
Purpose: to calculate divided value and remaining value
in form of tuple
Argument taken: 1.dividend required, 2.divisor required
Return: tuple
enumerate (iterable, start)
Purpose:
Argument taken: 1.iterable required, 2.start optional
default is 0
Return: enumerate
eval(expression, global, local)
Purpose: To Evaluate the given source (expression) in
the context of globals and locals
Argument taken:1.expression str required 2.global
optional, 3.local optional
Return: value
exec(object, global, locals)
Purpose: Execute the given source in the context of
globals and locals.
Argument taken: 1. Object The object may be a string
representing one or more Python statements
or a code object as returned by compile(),2.global
optional, 3. Locals optional
filter(function, iterable)
Purpose: to filter required specified value from
function
Argument taken: 1.function or None (Required), 2.
Iterable (required)
Return: filter
float(value)
Purpose: Convert a string or number to a floating point
number, if possible
Argument taken:1. Value(must be string of real
number(optional)default is 0
Return: float value
format (value, format)
Purpose: formats a specified value into a specified
format.
Argument taken: 1.value (required) 2. Format format you
want to format the value into.
Legal values:
'<' - Left aligns the result (within the available
space)
'>' - Right aligns the result (within the available
space)
'^' - Center aligns the result (within the available
space)
'=' - Places the sign to the left most position
'+' - Use a plus sign to indicate if the result is
positive or negative
'-' - Use a minus sign for negative values only
' ' - Use a leading space for positive numbers
',' - Use a comma as a thousand separator
'_' - Use a underscore as a thousand separator
'b' - Binary format
'c' - Converts the value into the corresponding unicode
character
'd' - Decimal format
'e' - Scientific format, with a lower case e
'E' - Scientific format, with an upper case E
'f' - Fix point number format
'F' - Fix point number format, upper case
'g' - General format
'G' - General format (using a upper case E for
scientific notations)
'o' - Octal format
'x' - Hex format, lower case
'X' - Hex format, upper case
'n' - Number format
'%' - Percentage format
Return: string
frozenset(iterable)
Purpose: Build an immutable unordered collection of
unique elements.
Argument taking: iterable optional
Return: frozenset object
getattr (object, attribute, message)
purpose:To get the value of the specified attribute
from the specified object.
argument taken:1. Object required, 2. Attribute
required,3 message optional if the value does not have
in the specified object this message will sown
return: value
globals()
Purpose: To show the dictionary containing the current
scope's global variables.
Argument taken: no any argument
Return: Dictionary
hasattr(object, attribute)
Purpose: the object has an attribute with the given
name.
Argument taken:1. Object required, 2.attribute required
Return: bool value
hex()
Purpose:To the hexadecimal representation of an
integer.
Argument taken:1.intiger required
Return: string
id(object)
Purpose:to show the identity of an object.

All objects in Python has its own unique id.

The id is assigned to the object when it is created.

The id is the object's memory address, and will be


different for each time you run the program. (except
for some object that has a constant unique id, like
integers from -5 to 256)

Argument taken: 1. object required


Return: identity of an object.
input(prompt)
Purpose:to take input from user
Argument taken:1.prompt optional
Return:string
int(value, base)
Purpose: To convert in to integer value
Argument taken: 1.value optional default is 0,2,base
optional
Return: integer
isinstance(object,type)
Purpose: To check whether an object is an instance of a
class or of a subclass thereof
Argument taken: 1. Object required, 2. Type required
Return: bool
Issubclass( Object, subclass)
Purpose: To check whether 'cls' is derived from
another class or is the same class.
Argument taken: 1.object required, 2. Subclass required
Return: bool
iter(object, sentinel)
Purpose: Get an iterator from an object. In the first
form, the argument must
supply its own iterator, or be a sequence.
In the second form, the callable is called until it
returns the sentinel.
Argument taken: 1.object required, 2. Sentinel optional
len(object)
purpose:To check the number of items in a container.
Argument taken: 1.object required
Return: int
list(iterable)
purpose:To generate list object
Argument taken: 1. Iterable optional
Return: list
locals()
purpose: To check dictionary containing the current
scope's local variables.
Argument taken: not taking any argument
Return: dictionary
map(function, iterable)
Purpose: function executes a specified function for
each item in an iterable. The item is sent to the
function as a parameter.
Argument taken: 1.function required, 2.iterable
required
Return: map
max(iterable)
Purpose: to findout maximum value in iterable
Argument taken: 1.iterable required
Return: value
min(iterable)
purpose: to findout minium value in iterable
Argument taken: 1.iterable required
Return: value
memoryview(object)
Purpose: Create a new memoryview object which references
the given object.
Argument taken: 1. byte object or bytearray object
required
Return:
next(iterable, default)
Purpose: Return the next item from the iterator. If
default is given and the iterator
is exhausted, it is returned instead of raising
StopIteration.
Argument taken: 1.iterable object required, 2.default
optional
Return:value
object()
purpose: To create an empty object
you cannot add new properties or methods for this
object
Argument taken: no required
Return: object
oct(int)
Purpose : convert a number into octal
Argument required: int number required
Return: string
open()
Purpose: To opens a file, and returns it as a file
object.
ord(character)
Purpose: the Unicode code point for a one-character
string.
Argument taken: 1.single character stirng required
Return: int
pow(base value, exponent value, for finding modulus
value )
Purpose: to calculate exponential value of the base
Argument taken: 1.base value required, 2. Exponent
value required, 3.for finding modulus optional
Return : int
print(object, sep=' ', end='\n', file=None,
flush=False)
Purpose: Prints the values to a stream, or to
sys.stdout by default.
Argument taken :1.object optional , 2.seprator optional
default (space), 3. End optional default new line,
4.file optional default none, 5.flush optional default
false
Return: NoneType
range(start, stop, step)
Purpose: an object that produces a sequence of integers
from start (inclusive)to stop (exclusive) by step.
Argument taken:1. Start optional default 0, 2,stop
required 3.step optional default is 1
Return: range
reversed(sequence)
Purpose: to make a reverse iterator over the values of
the given sequence.
Argument taken: 1.sequence required
Return : reversed object
round(number, digit)
Purpose:to roundup the digits
Arguments taken: 1.number required 2.digits optional
default 0
Return: float or intiger
set(iterable)
Purpose: to create set
Argument taken:1.iterable optional
Return: set
setattr(Object, attribute, value)
Purpose: Sets the named attribute on the given object
to the specified value
Argument taken: 1.object required, 2.attribute
required, 3. Value required
Return: None
slice(start, end, step)
Purpose: to create a slice object
Argument required: 1. Start optional default is 0, 2.
End required,3.step optional default is 1
Return : slice object
sorted(iterable, key=key, reverse=reverse)
You cannot sort a list that contains BOTH string values
AND numeric values.

You might also like