Loading... ## 变量 ``` message = "Hello Python world" ``` ### 字符串 ``` 'This is a string.' "This is a string." "That's it" 'The soilder said: " Victory to the soviet!"' ``` ### 字符串运算 ``` name = "\tada lovelace\n" print(name.title()) print(name.upper()) print(name.lower()) print(name.rstrip()) print(name.lstrip()) print(name.strip()) print(f"Hello {name.strip().title()}.") ``` 结果: ``` Ada Lovelace ADA LOVELACE ada lovelace ada lovelace ada lovelace ada lovelace Hello Ada Lovelace. ``` ### 数 ``` universe_age, minerals = 14_000_000_000, 15_0_00_00_0 #两数除法即使整除也是浮点 NEPTUNE_AGE = 20 #python 没有内置的常量类型, 全大写只是一种习惯 print(universe_age) print(minerals) print(f"{NEPTUNE_AGE}\n") import this ``` ``` 14000000000 15000000 20 The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those! ``` Last modification:February 14, 2022 © Allow specification reprint Like 如果觉得我的文章对你有用,请留下评论。