String in Python



Any values provided by the user in single quote ‘’ or double quote “” compiler treats as string

Syntax
Firstname="Rupesh"
print Firstname






String Manipulation functions
string.ascii_letters
string.ascii_lowercase
string.ascii_uppercase
string.digits
string.hexdigits
string.letters
string.lowercase
string.octdigits
string.punctuation
string.printable
string.uppercase
string.whitespace
capitalize()
center(width, fillchar)
count(str, beg= 0,end=len(string))
decode(encoding='UTF-8',errors='strict')
encode(encoding='UTF-8',errors='strict')
endswith(suffix, beg=0, end=len(string))   
expandtabs(tabsize=8)  
find(str, beg=0 end=len(string))      
index(str, beg=0, end=len(string))   
isalnum()
isalpha()     
isdigit()      
islower()     
isnumeric() 
isspace()    
istitle()       
isupper()    
join(seq)    
len(string)  
ljust(width[, fillchar])     
lower()       
lstrip()        
maketrans()
max(str)     
min(str)      
replace(old, new [, max])        
rfind(str, beg=0,end=len(string))     
rindex( str, beg=0, end=len(string)) 
rjust(width,[, fillchar])   
rstrip()        
split(str="", num=string.count(str))  
splitlines( num=string.count('\n'))    
startswith(str, beg=0,end=len(string))       
strip([chars])       
swapcase() 
title()
translate(table, deletechars="")        
upper()
zfill (width)
isdecimal()

String can be accessed based on index as well in Python
print firstname[0]
R
firstname="Rupesh"
 print firstname[2:4]
 pe
Escaping Character
Escape         Meaning
\newline      Ignored
\\                 Backslash (\)
\'                 Single quote (')
\"                 Double quote (")
\a                ASCII Bell (BEL)
\b                ASCII Backspace (BS)
\f                 ASCII Formfeed (FF)
\n                ASCII Linefeed (LF)
\r                 ASCII Carriage Return (CR)
\t                 ASCII Horizontal Tab (TAB)
\v                ASCII Vertical Tab (VT)
\ooo             ASCII character with octal value ooo
\xhh...         ASCII character with hex value hh...

Splitting a string
·         split  splits the string using specific literal.

Ex:.
alphabet = "a b c d e f g"
lstdata = alphabet.split()
for letter in lstdata:
 print letter

Formatter Syntax

%c     character
%s     string conversion via str() prior to formatting
%i      signed decimal integer
%d    signed decimal integer
%u    unsigned decimal integer
%o     octal integer
%x     hexadecimal integer (lowercase letters)
%X    hexadecimal integer (UPPERcase letters)
%e     exponential notation (with lowercase 'e')
%E    exponential notation (with UPPERcase 'E')
%f     floating point real number
%g    the shorter of %f and %e
%G    the shorter of %f and %E
String in Python Reviewed by Rupesh on 04:13 Rating: 5

No comments:

All Rights Reserved by Technology from Developers Eye © 2014 - 2015
Powered By Blogger, Designed by Aadics
Disclaimers:: The information provided within this blogsite is for general informational purposes only. While we try to keep the information up-to-date and correct, there are no representations or warranties, express or implied, about the completeness, accuracy, reliability, suitability or availability with respect to the information, products, services, or related graphics contained in this blogsite for any purpose.The author does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause.

Contact Form

Name

Email *

Message *

Powered by Blogger.