In Python, “typeerror: not all arguments converted during string formatting” primarily occurs when:
# Since `x` is a string, the `%` operator is treated as a string# interpolation operator. The error occurs because no format specifier# is provided.x = "11"if(x % 2):print("x is odd")
x = "11"# This tells the compiler that % is used as the modulus operatorif(int(x) % 2):print("x is odd")
fav_food = "pizza"fav_show = "Friends"fav_day = "Saturday"fav_month = "June"print("I like to eat %s while watching %s." % (fav_day, fav_food, fav_month, fav_show))
fav_food = "pizza"fav_show = "Friends"fav_day = "Saturday"fav_month = "June"print("I like to eat %s while watching %s." % (fav_food, fav_show))
fav_food = "pizza"fav_show = "Friends"print ("I like to eat '{0}' while watching '{1}'." % fav_food, fav_show)
fav_food = "pizza"fav_show = "Friends"print ("I like to eat %s while watching %s." % (fav_food, fav_show))
fav_food = "pizza"fav_show = "Friends"print ("I like to eat {0} while watching {1}.".format(fav_food, fav_show))
Free Resources