program name at the front slices are also often used to clean up lines read from input files if you know that line will have an end-of-line character at the end ( \ newline marker)you can get rid of it with single expression such as line[:- ]which extracts all but the last character in the line (the lower limit defaults to in both casesslices do the job of logic that must be explicit in lower-level language having said thatcalling the line rstrip method is often preferred for stripping newline characters because this call leaves the line intact if it has no newline character at the end-- common case for files created with some text-editing tools slicing works if you're sure the line is properly terminated string conversion tools one of python' design mottos is that it refuses the temptation to guess as prime exampleyou cannot add number and string together in pythoneven if the string looks like number ( is all digits)python " typeerrorcan' convert 'intobject to str implicitly python " typeerrorcannot concatenate 'strand 'intobjects this is by designbecause can mean both addition and concatenationthe choice of conversion would be ambiguous insteadpython treats this as an error in pythonmagic is generally omitted if it will make your life more complex what to dothenif your script obtains number as text string from file or user interfacethe trick is that you need to employ conversion tools before you can treat string like numberor vice versa for instanceint(" ")str( ( ' 'repr( ' convert from/to string convert to as-code string the int function converts string to numberand the str function converts number to its string representation (essentiallywhat it looks like when printedthe repr function (and the older backquotes expressionremoved in python xalso converts an object to its string representationbut returns the object as string of code that can be rerun to recreate the object for stringsthe result has quotes around it if displayed with print statementwhich differs in form between python linesprint(str('spam')repr('spam')spam 'spam xprint str('spam')repr('spam'strings in action