Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请用代码描述如何使用fstring格式化字符串 #52

Open
Sogrey opened this issue Feb 16, 2020 · 0 comments
Open

请用代码描述如何使用fstring格式化字符串 #52

Sogrey opened this issue Feb 16, 2020 · 0 comments

Comments

@Sogrey
Copy link
Owner

Sogrey commented Feb 16, 2020

name = 'Bill'
age = 20

def getAge():
    return 21

s = f"我是{name},我今年{age}岁,明年{getAge()}岁"

print(s)

class Person:
    def __init__(self):
        self.name = 'Mike'
        self.age = 40
    def getAge(self):
        return 41

person = Person()

s1 = f"我是{person.name},我今年{person.age}岁,明年{person.getAge()}岁"
print(s1)

fstring方式是指在字符串中直接使用Python变量,这需要在字符串前面用f标注。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Python QAs
正则表达式
Development

No branches or pull requests

1 participant