The application of the Python programming language is a good computer programming language for developers. In practice, the application of strings is a basic operation technology. Today, we will give you a detailed introduction to the operations related to Python string display.
Maybe I haven't found a better method yet, but unfortunately, Python does not seem to support scalar interpolation like shell scripts and perl currently, therefore, it is impossible to display such a personal feeling as follows. This is the clearest and most convenient method.
For example, if a user loses two variables: 'bucketball ', 'bucketing', shell, or per, the following shows I love bucketball and specify the best.
- #shell
- input = 'basketball'
- input2 = 'swimming'
- print 'I love $input and $input2 the best'
- #perl
- $input = 'basketball'
- $input2 = 'swimming'
- print 'I love $input and $input2 the best'
How to Implement Python string display? There are the following methods: select as needed. I hope to directly support the display method similar to the escape script in the future, and regard $ as an escape character :)
- import sys
- input = sys.argv[1]
- input2 = sys.argv[2]
- s = 'I love ' + input + ' and ' + input2 + ' the best'
- print(s)
- s = 'I love %s and %s the best'%(input, input2)
- print(s)
- params= {'input': input, 'input2': input2 }
- s = 'I love %(input)s and %(input2)s the best'%params
- 13 print(s)
- from string import Template
- s = Template('I love $input and $input2 the best')
- ss =s.substitute(inputinput=input, input2input2=input2)
- print(s)
The preceding section describes how to display Python strings.