Created
June 15, 2017 21:43
-
-
Save vijayanandrp/30fc0162e36ab507709ba1f8e347987c to your computer and use it in GitHub Desktop.
How to do I understand strings Python concepts in just 5 mins!!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| def main(): | |
| print int('5') | |
| print ord('s') | |
| print chr(115) | |
| print bin(13) | |
| print hex(26) | |
| print hex(255) | |
| print oct(255) | |
| print bin(255) | |
| print int('377', 8), int('FF', 16) | |
| print str('Vijay') | |
| print repr('Vijay') # Removed in 3.X python | |
| line = "The knights who say N1!\n" | |
| print line.endswith('\n') | |
| print line.startswith('The'), '\n' | |
| print '%(qty)d more %(food)s' % {'qty': 1, 'food': 'Dosai'}, '\n' | |
| # Method 1 of formatting output | |
| values = {} | |
| values = dict(name='Vijay', job='testing', age=24) | |
| print 'Hi Guys, My name is %(name)s and age is %(age)d. My Current job is %(job)s' % values, '\n' | |
| # Method 2 of formatting | |
| template = '{0}, {1} and {2}' | |
| print template.format('spam', 'ham', 'eggs') | |
| template = '{}, {} and {}' | |
| print template.format('spam', 'ham', 'eggs') | |
| template = '{motto}, {pork} and {food}' | |
| print template.format(motto='spam', pork='ham', food='eggs') | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment