I would like to concatenate strings and variable values in Python 3.
For instance, in R I can do the following:
today <- as.character(Sys.Date())
paste0("In ", substr(today,1,4), " this can be an R way")
Executing this code in R yields [1] "In the year 2018 R is so straightforward".
In Python 3.6 have tried things like:
today = datetime.datetime.now()
"In year " + today.year + " I should learn more Python"
today.year on its own yields 2018, but the whole concatenation yields the error: 'int' object is not callable
What's the best way to concatenate strings and variable values in Python3?
sprintfin R? the same can be accomplished in python by applying the % operator to a string. you can also.formata string."In year " + str(today.year) + " I should learn more Python".'int' object is not callable', I would expect aTypeErrorsayingcannot concatenate 'str' and 'int' objects.