Python String Örnekler

Hamdi Yılmaz
Dec 9, 2021

--

datestr = '1956-01-31'
year, month, day = datestr.split('-')
'/'.join([month, day, year])

Farklı bitane

claim = "Pluto is a planet!"
words = claim.split() # default olarak boşluklardan ayırır

# Yes, we can put unicode characters right in our string literals :)

' 👏 '.join([word.upper() for word in words])

print içinde genelde kullandığımız yöntem

"{}, you'll always be the {}th planet to me.".format(planet, position)

üsttekinin ileri seviye kullanımı

pluto_mass = 1.303 * 10**22
earth_mass = 5.9722 * 10**24
population = 52910390
# 2 decimal points 3 decimal points, format as percent separate with commas
"{} weighs about {:.2} kilograms ({:.3%} of Earth's mass). It is home to {:,} Plutonians.".format(
planet, pluto_mass, pluto_mass / earth_mass, population,
)

# Referring to format() arguments by index, starting from 0
s = """Pluto's a {0}.
No, it's a {1}.
{0}!
{1}!""".format('planet', 'dwarf planet')
print(s)

--

--

No responses yet