s="whatdoyoumeanwhat" w="what" sup="------------------------------------------" float=1.12 years=20 #appears bellow print (len("a")) print (len("abdfd")) #len("string") length de uma string print(len(s)) #printing word what character by character print((s[13])) print((s[14])) print((s[15])) print((s[16])) print("what"+"do"+"you") #concatenation print(w+"do"+"you") #variable contains string print(w+"do"+"you"*3) #multiplication print(w+"-"*11+w) #wat print(sup) print("HOW MANY YEARS DO YOU HAVE?") print(sup) years=40 print("YOU HAVE"+" years"*years) print("%d years") % years # %d marking. in this case for integers. print(sup) print("%s you mean: WHAT DO YOU MEAN") % s # %s marking for strings print(w+" %f") % float # %f float marking print(sup) print("[%9d]") % years #print 40 between brakets but take up 5 characters, add blank if necessary print("[%05d]") % years #print 40 between brakets but take up 5 characters, add ZEROES if necessary print("[%-9d]") % years #same as above but this time do it from right to left print(sup) print("FLOAT CHARACTER CONTROL") print (sup) print ("[%8.3f]" % 6) #number after comma controls range after comma. print ("[%20.4f]" % float) #number before comman should do the same for range b4 comma print ("[%7.1f]" % float) #both these numbers share the space bofore the comma. print(sup) print("FLOAT CHARACTER play") print (sup) nome="luiz" anos=21 grana=62.45 #62 reais e 45 centavos print("olá meu nome é %s e eu tenho %d anos de idade, tenho %f no bolso :D" %(nome,anos,grana)) #notice the float printing zeros print("olá meu nome é %s e eu tenho %d anos de idade, tenho %4.2f no bolso :D" %(nome,anos,grana)) #a.b : b is immediately sensitive to changes. a only matters if it exceeds the ammount of numbers that would normally print print(sup) print("string slicin") print (sup) print(s[0:4]+" "+s[4:6]+" "+s[6:9]+" "+s[9:13]+" "+s[13:18]) #python range does not include the last number! print(s[:4]) #until 4th character print (s[4:]) #4th onwards print(s[-4:]) #last four character. 4 counted from end of string until beginnig
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