Skip to content

Instantly share code, notes, and snippets.

@Kamori
Created January 19, 2017 01:44
Show Gist options
  • Save Kamori/cbd685bba63ad67b47db9dd0bea6fe18 to your computer and use it in GitHub Desktop.
Save Kamori/cbd685bba63ad67b47db9dd0bea6fe18 to your computer and use it in GitHub Desktop.
# prompt for a name
name = raw_input('Give me a name: ')
# output of name
print name
###
# Print name in a string
###
# Bad practice, hard to read
print 'Hello' + name
# Better but getting phased out
print 'Hello %s nice to meet you' % name
# My preferred
print 'Hello there {0}. Nice weather'.format(name)
# However you can be more verbose
another_variable = 'Tom'
print 'Hey {otherperson}, look its {coder}!'.format(otherperson=another_variable, coder=name)
# prompt for a name
name = input('Give me a name: ')
# output of name
print(name)
###
# Print name in a string
###
# Bad practice hard to read
print('Hello' + name)
# Better but getting phased out
print('Hello %s nice to meet you') % name
# My preferred
print('Hello there {0}. Nice weather').format(name)
# However you can be more verbose
another_variable = 'Tom'
print('Hey {otherperson}, look its {coder}!').format(otherperson=another_variable, coder=name)
# New in 3.6
print(f'Hey {name}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment