5200.2.1 String

02 Variables and Simple Data Types

String 由一系列字符组成,任何被引号包围的字符,都是String.

Function

  • title()
  • upper()
  • lower()
  • rstrip()
  • lstrip()
  • strip()
  • removeprefix()

Adding Whitespace to Strings with Tabs or Newlines

print("Python")
print("\tPython")
print("Languages:\nPython\nC\nJavaScript")
print("Languages:\n\tPython\n\tC\n\tJavaScript")

f-strings

first_name = "ada"
 
last_name = "lovelace"
 
full_name = f"{first_name} {last_name}"
 
print(f"Hello, {full_name.title()}!")