str = "This is a string" print "string:", str #str = str.swapcase() print "swapcase: ", str.swapcase() print "title: ", str.title() print "upper: ", str.upper() print "lower: ", str.lower() strnumb = "123" print "number ", strnumb print "zfill filled number ", strnumb.zfill(20) print "zfill filled number ", str.zfill(20) print str[0] print str[0:4] print "find ", str.find("is") print str.replace(" ","") spacy = " this is a spacy string " print spacy print spacy.lstrip() print spacy.rstrip() print spacy.strip() startstring = "this string starts @ with this !" if startstring.startswith("his"): print "yes" else: print "no" atpos = startstring.find('@') print startstring, " atpos ", atpos expos = startstring.find('!',atpos) print startstring, " expos ", expos print startstring[atpos + 1:expos] print startstring[atpos + 1:expos].strip() print len(startstring) #while loop through strings index = 0 while index < len(str): #print str[index] index = index + 1 #for loop through string count = 0 for letter in str: #print letter if letter == 'a': count = count + 1 print "count of string letters a: ", count
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question