Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 80 characters in body
Source Link
Blender
  • 300.1k
  • 55
  • 462
  • 511
  1. Use the new-style string formatting:

     print("Total score for {} is {}".format(name, score)) 
  2. Use the new-style string formatting with numbers (useful for reordering or printing the same one multiple times):

     print("Total score for {0} is {1}".format(name, score)) 
  3. Use the new-style string formatting with explicit names:

     print("Total score for {n} is {s}".format(n=name, s=score)) 
  4. Concatenate strings:

     print("Total score for " + str(name) + " is " + str(score)) 
  1. Pass the values as parameters and print will do it:

     print("Total score for", name, "is", score) 

    If you don't want spaces to be inserted automatically by print in the above example, change the sep parameter:

     print("Total score for ", name, " is ", score, sep='') 

    If you're using Python 2, won't be able to use the last two because print isn't a function in Python 2. You can, however, import this behavior from __future__:

     from __future__ import print_function 
  2. Use the new f-string formatting in Python 3.6:

     print(f'Total score for {name} is {score}') 
  1. Just pass the values as parameters:

     print("Total score for", name, "is", score) 

    If you don't want spaces to be inserted automatically by print in the above example, change the sep parameter:

     print("Total score for ", name, " is ", score, sep='') 

    If you're using Python 2, won't be able to use the last two because print isn't a function in Python 2. You can, however, import this behavior from __future__:

     from __future__ import print_function 
  2. Use the new f-string formatting in Python 3.6:

     print(f'Total score for {name} is {score}') 
  1. Use the new-style string formatting:

     print("Total score for {} is {}".format(name, score)) 
  2. Use the new-style string formatting with numbers (useful for reordering or printing the same one multiple times):

     print("Total score for {0} is {1}".format(name, score)) 
  3. Use the new-style string formatting with explicit names:

     print("Total score for {n} is {s}".format(n=name, s=score)) 
  1. Pass the values as parameters and print will do it:

     print("Total score for", name, "is", score) 

    If you don't want spaces to be inserted automatically by print in the above example, change the sep parameter:

     print("Total score for ", name, " is ", score, sep='') 

    If you're using Python 2, won't be able to use the last two because print isn't a function in Python 2. You can, however, import this behavior from __future__:

     from __future__ import print_function 
  2. Use the new f-string formatting in Python 3.6:

     print(f'Total score for {name} is {score}') 
  1. Use new-style string formatting:

     print("Total score for {} is {}".format(name, score)) 
  2. Use new-style string formatting with numbers (useful for reordering or printing the same one multiple times):

     print("Total score for {0} is {1}".format(name, score)) 
  3. Use new-style string formatting with explicit names:

     print("Total score for {n} is {s}".format(n=name, s=score)) 
  4. Concatenate strings:

     print("Total score for " + str(name) + " is " + str(score)) 
  1. Just pass the values as parameters:

     print("Total score for", name, "is", score) 

    If you don't want spaces to be inserted automatically by print in the above example, change the sep parameter:

     print("Total score for ", name, " is ", score, sep='') 

    If you're using Python 2, won't be able to use the last two because print isn't a function in Python 2. You can, however, import this behavior from __future__:

     from __future__ import print_function 
  2. Use the new f-string formatting in Python 3.6:

     print(f'Total score for {name} is {score}') 
added 40 characters in body
Source Link
Blender
  • 300.1k
  • 55
  • 462
  • 511

There are many ways to do this. To fix your current code using %-formatting, you need to pass in an iterable like a tuple:

  1. Pass it as a tuple:

     print("Total score for %s is %s" % (name, score)) 

A tuple with a single element looks like ('this',).

Here are some other common ways of doing it:

  1. Pass it as a dictionary:

     print("Total score for %(n)s is %(s)s" % {'n': name, 's': score}) 

There's also new-style string formatting, which might be a little easier to read:

  1. Use the new-style string formatting:

     print("Total score for {} is {}".format(name, score)) 
  2. Use the new-style string formatting with numbers (useful for reordering or printing the same one multiple times):

     print("Total score for {0} is {1}".format(name, score)) 
  3. Use the new-style string formatting with explicit names:

     print("Total score for {n} is {s}".format(n=name, s=score)) 

The clearest two, in my opinion:

  1. Pass the values as parameters and print will do it:

     print("Total score for", name, "is", score) 

    If you don't want spaces to be inserted automatically by print in the above example, change the sep parameter:

     print("Total score for ", name, " is ", score, sep='') 

    If you're using Python 2, won't be able to use the last two because print isn't a function in Python 2. You can, however, import this behavior from __future__:

     from __future__ import print_function 
  2. Use the new f-string formatting in Python 3.6:

     print(f'Total score for {name} is {score}') 

There are many ways to do this. To fix your current code using %-formatting, you need to pass in an iterable like a tuple:

  1. Pass it as a tuple:

     print("Total score for %s is %s" % (name, score)) 

Here are some other common ways of doing it:

  1. Pass it as a dictionary:

     print("Total score for %(n)s is %(s)s" % {'n': name, 's': score}) 

There's also new-style string formatting, which might be a little easier to read:

  1. Use the new-style string formatting:

     print("Total score for {} is {}".format(name, score)) 
  2. Use the new-style string formatting with numbers (useful for reordering or printing the same one multiple times):

     print("Total score for {0} is {1}".format(name, score)) 
  3. Use the new-style string formatting with explicit names:

     print("Total score for {n} is {s}".format(n=name, s=score)) 

The clearest two, in my opinion:

  1. Pass the values as parameters and print will do it:

     print("Total score for", name, "is", score) 

    If you don't want spaces to be inserted automatically by print in the above example, change the sep parameter:

     print("Total score for ", name, " is ", score, sep='') 

    If you're using Python 2, won't be able to use the last two because print isn't a function in Python 2. You can, however, import this behavior from __future__:

     from __future__ import print_function 
  2. Use the new f-string formatting in Python 3.6:

     print(f'Total score for {name} is {score}') 

There are many ways to do this. To fix your current code using %-formatting, you need to pass in a tuple:

  1. Pass it as a tuple:

     print("Total score for %s is %s" % (name, score)) 

A tuple with a single element looks like ('this',).

Here are some other common ways of doing it:

  1. Pass it as a dictionary:

     print("Total score for %(n)s is %(s)s" % {'n': name, 's': score}) 

There's also new-style string formatting, which might be a little easier to read:

  1. Use the new-style string formatting:

     print("Total score for {} is {}".format(name, score)) 
  2. Use the new-style string formatting with numbers (useful for reordering or printing the same one multiple times):

     print("Total score for {0} is {1}".format(name, score)) 
  3. Use the new-style string formatting with explicit names:

     print("Total score for {n} is {s}".format(n=name, s=score)) 

The clearest two, in my opinion:

  1. Pass the values as parameters and print will do it:

     print("Total score for", name, "is", score) 

    If you don't want spaces to be inserted automatically by print in the above example, change the sep parameter:

     print("Total score for ", name, " is ", score, sep='') 

    If you're using Python 2, won't be able to use the last two because print isn't a function in Python 2. You can, however, import this behavior from __future__:

     from __future__ import print_function 
  2. Use the new f-string formatting in Python 3.6:

     print(f'Total score for {name} is {score}') 
added 171 characters in body
Source Link
Blender
  • 300.1k
  • 55
  • 462
  • 511

There are many ways to do this. To fix your current code using %-formatting, you need to pass in an iterable like a tuple:

  1. Pass it as a tuple:

     print("Total score for %s is %s" % (name, score)) 
  2. Or use the new-style string formatting:

     print("Total score for {} is {}".format(name, score)) 
  3. Or pass the values as parameters and print will do it:

     print("Total score for", name, "is", score) 

    If you don't want spaces to be inserted automatically by print in the above example, change the sep parameter:

     print("Total score for ", name, " is ", score, sep='') 

    If you're using Python 2, won't be able to use the last two because print isn't a function in Python 2. You can, however, import this behavior from __future__:

     from __future__ import print_function 
  4. Or use the new f-string formatting in Python 3.6:

     print(f'Total score for {name} is {score}') 

Here are some other common ways of doing it:

  1. Pass it as a dictionary:

     print("Total score for %(n)s is %(s)s" % {'n': name, 's': score}) 

There's also new-style string formatting, which might be a little easier to read:

  1. Use the new-style string formatting:

     print("Total score for {} is {}".format(name, score)) 
  2. Use the new-style string formatting with numbers (useful for reordering or printing the same one multiple times):

     print("Total score for {0} is {1}".format(name, score)) 
  3. Use the new-style string formatting with explicit names:

     print("Total score for {n} is {s}".format(n=name, s=score)) 

The clearest two, in my opinion:

  1. Pass the values as parameters and print will do it:

     print("Total score for", name, "is", score) 

    If you don't want spaces to be inserted automatically by print in the above example, change the sep parameter:

     print("Total score for ", name, " is ", score, sep='') 

    If you're using Python 2, won't be able to use the last two because print isn't a function in Python 2. You can, however, import this behavior from __future__:

     from __future__ import print_function 
  2. Use the new f-string formatting in Python 3.6:

     print(f'Total score for {name} is {score}') 
  1. Pass it as a tuple:

     print("Total score for %s is %s" % (name, score)) 
  2. Or use the new-style string formatting:

     print("Total score for {} is {}".format(name, score)) 
  3. Or pass the values as parameters and print will do it:

     print("Total score for", name, "is", score) 

    If you don't want spaces to be inserted automatically by print in the above example, change the sep parameter:

     print("Total score for ", name, " is ", score, sep='') 

    If you're using Python 2, won't be able to use the last two because print isn't a function in Python 2. You can, however, import this behavior from __future__:

     from __future__ import print_function 
  4. Or use the new f-string formatting in Python 3.6:

     print(f'Total score for {name} is {score}') 

There are many ways to do this. To fix your current code using %-formatting, you need to pass in an iterable like a tuple:

  1. Pass it as a tuple:

     print("Total score for %s is %s" % (name, score)) 

Here are some other common ways of doing it:

  1. Pass it as a dictionary:

     print("Total score for %(n)s is %(s)s" % {'n': name, 's': score}) 

There's also new-style string formatting, which might be a little easier to read:

  1. Use the new-style string formatting:

     print("Total score for {} is {}".format(name, score)) 
  2. Use the new-style string formatting with numbers (useful for reordering or printing the same one multiple times):

     print("Total score for {0} is {1}".format(name, score)) 
  3. Use the new-style string formatting with explicit names:

     print("Total score for {n} is {s}".format(n=name, s=score)) 

The clearest two, in my opinion:

  1. Pass the values as parameters and print will do it:

     print("Total score for", name, "is", score) 

    If you don't want spaces to be inserted automatically by print in the above example, change the sep parameter:

     print("Total score for ", name, " is ", score, sep='') 

    If you're using Python 2, won't be able to use the last two because print isn't a function in Python 2. You can, however, import this behavior from __future__:

     from __future__ import print_function 
  2. Use the new f-string formatting in Python 3.6:

     print(f'Total score for {name} is {score}') 
added 171 characters in body
Source Link
Blender
  • 300.1k
  • 55
  • 462
  • 511
Loading
added 216 characters in body
Source Link
Blender
  • 300.1k
  • 55
  • 462
  • 511
Loading
added 154 characters in body
Source Link
Blender
  • 300.1k
  • 55
  • 462
  • 511
Loading
added 111 characters in body
Source Link
Blender
  • 300.1k
  • 55
  • 462
  • 511
Loading
Source Link
Blender
  • 300.1k
  • 55
  • 462
  • 511
Loading