Python
-
String FormattingPython 2014. 5. 11. 00:21
ConversionMeaningNotes'd'Signed integer decimal. 'i'Signed integer decimal. 'o'Signed octal value.(1)'u'Obsolete type – it is identical to 'd'.(7)'x'Signed hexadecimal (lowercase).(2)'X'Signed hexadecimal (uppercase).(2)'e'Floating point exponential format (lowercase).(3)'E'Floating point exponential format (uppercase).(3)'f'Floating point decimal format.(3)'F'Floating point decimal format.(3)'g..
-
String short version & TemplatePython 2014. 5. 10. 23:43
website = 'www.python.com' print (website) print (website[4:]) print (website[-3]) print (website[-3:]) website = 'www.%s.%s' value = ('yahoo','com') print (website % value) format = 'pi with 3 decimal points %.3f' from math import pi print (format % pi) from string import Template s = Template('$x, glorois $x') print(s.safe_substitute(x='Kiss')) a = Template('A $thing must be never $action.') d..
-
List & List member functionPython 2014. 5. 9. 06:39
names = ['hong', 'song', 'ra'] del names[2] names.append('kang') names2 = ['brown', 'chris', 'maria'] names.insert(2, 'koa') names.pop() if names.count('hong') > 0 : print ('index of hong is ' + str(names.index('hong'))) names.remove('hong') names[1] = 'kong' print (names) names.sort(key=None, reverse=False) print (names) names.reverse() print (names)
-
연속된 문자열 처리Python 2014. 5. 7. 23:32
"x"*10 -à "xxxxxxxxxx" "xyz"*2 --? "xyzxyz" sentence = input("enter sentence : ") screen_width = 80 text_width = len(sentence) box_width = text_width + 6; left_margin = screen_width//2 - box_width//2 print() print(" "*left_margin+"+"+"-"*(box_width)+"+") print(" "*left_margin+"|"+" "*(box_width)+"|") print(" "*left_margin+"|"+" "*3+sentence+" "*3+"|") print(" "*left_margin+"|"+" "*(box_width)+"|..