-1

So I've been writing simple python functions to test out methods and learn what they do, but many times I'll run the code and nothing happens. I'm very confused because I've checked the syntax but it just doesn't do anything.

Country = "italy"
if Country == "italy":
    Country.capitalize()
    Country.center(15)

print(Country)

this should printout ' Italy ' or something similar but it just returns "italy" everytime. I tried the methods seperately and they seem to work.

2 Answers2

0

Try:

country = "italy"
if country == "italy":
    country = Country.capitalize()
    country = Country.center(15)

print(country)
timko.mate
  • 364
  • 1
  • 3
  • 13
0

Like @Carcigenicate said the function Capitalize() returns a string. You would have to assign the returned string to your variable Capitalize. Example:

Country = "italy"
if Country == "italy":
    Country = Country.capitalize()
    Country = Country.center(15)

print(Country)

You can view the official documentation here which describes the input and return type of the function.

einelson
  • 1
  • 1