[Çözüldü] String Biçimlendirme

Başlatan lrnyrd, 11 Mayıs 2017 - 22:35:13

« önceki - sonraki »

0 Üyeler ve 1 Ziyaretçi konuyu incelemekte.

lrnyrd

Merhaba arkadaşlar kullandığım python sürümü 3.5.3 * bir şey sormak istiyorum elimde aşağıdaki gibi örnek varda normalde string biçimlendirmenin eski ve yeni yöntemini biliyorum ancak bununla ilk defa karşılaştım. Yalnız çalıştırdığımda ilk print satırında yazım hatası alıyorum. Bu örneğin geçtiği sitedeki python sürümü 3.6 acaba sürümden mi kaynaklanıyor yoksa bu biçimlendirmemi hatalı. Cevaplarınızı bekliyorum.

my_name = 'Zed A. Shaw'
my_age = 35 # not a lie
my_height = 74 # inches
my_weight = 180 # lbs
my_eyes = 'Blue'
my_teeth = "White"
my_hair = 'Brown'

print(f"Let's talk about {my_name}.")
print(f"He's {my_height} inches tall.")
print(f"He's {my_weight} pounds heavy.")
print("Actually that's not too heavy.")
print(f"He's got {my_eyes} eyes and {my_hair} hair.")
print(f"His teeth are usually {my_teeth} depending on the coffee.")

# this line is tricky, try to get it exactly right
total = my_age + my_height + my_weight
print(f"If I add {my_age}, {my_height}, and {my_weight} I get {total.}")
Sometimes even good memories can kill you!

mgunez

my_name = 'Zed A. Shaw'
my_age = int(35) # not a lie
my_height = int(74) # inches
my_weight = int(180) # lbs
my_eyes = "Blue"
my_teeth = "White"
my_hair = "Brown"

print("Let's talk about" +  my_name)
print("He's ", str(my_height) + "inches tall.")
print("He's " ,str(my_weight) + " pounds heavy.")
print("Actually that's not too heavy.")
print("He's got "+ my_eyes +" eyes and "+ my_hair + " hair.")
print(f"His teeth are usually "+ my_teeth +" depending on the coffee.")

# this line is tricky, try to get it exactly right
total = int(my_age + my_height + my_weight)
print("If I add ", str(my_age) +", "+str(my_height)+", and ", str(my_weight) + "I get ", str(total))


şeklinde yaparsan olur :) umarım yardımcı olabilmişimdir.

lrnyrd

#2
[mention=625266]@mgunez[/mention] cevabınız için teşekkürler ama bundan bahsetmiyorum sizin yaptığınız gibi karakter birleştirme, eski % ile format biçimleme ve format() ile biçimlendirmeyi zaten biliyorum benim sormak istediğim ilk gönderideki biçimlendirme python 3.6 da varmı yoksa yanlışmı yapılmış.


Mesaj tekrarı yüzünden mesajınız birleştirildi. Bu mesajın gönderim tarihi : 12 Mayıs 2017 - 09:25:43

Sorunum çözüldü arkadaşlar. Python 3.6 da f string gelmiş PEP 498
Sometimes even good memories can kill you!