name = input(enter name)
age = input(age)
print(“My name is print(name). I’m print(age) years old.”)
諾比實驗。初級任務。我想到了上述查詢。
uj5u.com熱心網友回復:
name = input("enter name: ")
age = input("age: ")
print(f"My name is {name}. I am {age} years old")
uj5u.com熱心網友回復:
研究并嘗試理解 Keshav V. 使用 f 弦的答案,這是“現代”方法,一次又一次地為您服務。
一個更長期的方法是像這樣重寫你的程式(作為理解 f-string 格式的墊腳石)。
name = input("enter name ")
age = input("age ")
print("My name is", name, "I’m", age, "years old.")
請注意,print將接受您要列印的所有專案并將它們放在同一行。
uj5u.com熱心網友回復:
捕獲名稱和年齡變數中的輸入后,您還可以使用f 字串格式。
print(f"My name is {name}. I'm {age} years old")
My name is laura. I'm 18 years old
uj5u.com熱心網友回復:
您可以簡單地使用 python f-strings。
name = input('Enter your name ')
age = input ('Enter your age ')
print(f'My name is {name}. I\'m {age} years old.')
如果您還想要,可以使用格式功能。
uj5u.com熱心網友回復:
或這個
name = input('Enter your name ')
age = input ('Enter your age ')
print('some text' name 'also some text')
祝你編程順利,
uj5u.com熱心網友回復:
您也可以嘗試字串格式化。
name = input('Enter your name ')
age = input ('Enter your age ')
print('My name is {}. I\'m {} years old.').format(name,age)
有關字串格式的更多資訊
uj5u.com熱心網友回復:
花一些時間閱讀一本 Python 書籍是個好主意。
name = input("enter name")
age = input("age")
print( f"My name is {name}. I'm {age} years old.")
uj5u.com熱心網友回復:
您可以為此使用格式化字串:
def name_and_age(name, age):
return f"My name is {name} and I'am {age} years old"
print(name_and_age('Max', 35))
#output: My name is Max and I'am 35 years old
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/533724.html
標籤:Python变量输入
