0

ユーザー名をドメインで分割するコードを作成する必要があります。

元。

入力: abc@xyz.com

出力: ユーザー名は abc です。あなたのドメインは xyz.com です。

結果は2つの異なる行であると思われますが、それを取得できないようです...

def username2(email):
    z=(email.split('@'))
    x='Your username is'+ ' ' + z[0]
    y='Your domain is' + ' ' + z[1]
    return x+'. '+y+'.'

申し訳ありません..私は本当に初心者です。

4

3 に答える 3

4

結果に改行文字を挿入する必要があります。

return x + '. \n' + y + '.'

文字列フォーマットを使用することもできます:

username, domain = email.split('@')

return 'Your username is {}.\nYour domain is {}.'.format(username, domain)
于 2013-03-22T01:06:08.983 に答える
1

エスケープコードはあなたが探しているものです

print "1 行目 \n2 行目"

http://docs.python.org/2/reference/lexical_analysis.html#literals

于 2013-03-22T01:07:38.980 に答える
0

Python3

def username2(email):
    username, domain = email.split('@')
    print('Your username is {}'.format(username))
    print('Your domain is {}'.format(domain))

Python2

def username2(email):
    username, domain = email.split('@')
    print 'Your username is %s' % username
    print 'Your domain is %s' % domain
于 2014-07-09T22:10:37.650 に答える