TypeError: not enough arguments for format string

em bị lỗi TypeError: not enough arguments for format string

print ("He's got %s eyes and %s hair." % my_eyes,  my_hair)

code của e đây ạ

Thực ra nó là ntn.

(fs % a), b # toạch

Dấu phẩy không phải operator, mà là built-in (như print hồi xưa) :smiley: nó nằm ngoài thang operator.

6 Likes

Nếu bạn muốn print cái string (có chứ variable), thì có thể làm như thế này (Python3)

my_eyes = "green"
my_hair = "blue"

print("#1. He's got {} eyes and {} hair".format(my_eyes,  my_hair))
print("#2. He's got %s eyes and %s hair"  %(my_eyes, my_hair))

#1. He’s got green eyes and blue hair
#2. He’s got green eyes and blue hair
[Finished in 0.3s]

3 Likes
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?