![](/img/trans.png)
[英]How can I make a variable for each person in my discord server with python?
[英]How can I make an invitation for each person?
我是編程新手,我必須挑戰列表上的每個人都可以得到邀請,但是我敢肯定必須有一種更簡單的方法,而不是更改guest_list[x]
7次。 這是我設法做到的。 請隨時批評我。
plus_one= 'hitler'
guest_list = ['john carter', 'emilia airheart', 'god']
print ("Dear, \n" + guest_list[1].title() + ", you are invited to a warm get together. unfortunately " + busy.title(),"couldn't make it "
+ "but luckily " + plus_one.title() + " managed to appear" )
guest_list.append('hitler')
guest_list.insert(-3, "bob ross")
guest_list.insert(0, 'jerry seinfeld')
guest_list.append('micheal')
print(guest_list)
這是您要找的東西嗎?
for guest in guest_list:
print ("Dear, \n" + guest.title() + ", you are invited to a warm get
together. unfortunately " + busy.title(),"couldn't make it "
+ "but luckily " + plus_one.title() + " managed to appear")
為了對來賓列表中的每個條目執行操作,您可以運行循環:
簡單的例子:
for guest in guest_list:
print guest
現在,您可以定義一個函數,將來賓的名字插入字符串並打印出來。 然后在循環中調用該函數。
這是非常基本的Python。 在問更多問題之前,您應該先做一個初學者教程。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.